全部博文(1144)
分类: LINUX
2011-12-08 20:39:48
I have a simple perl script (see below) which inserts a sample record.
I got this script from http://blogs.perl.org/users/kchodorow/2010/09/trying-out-replica-sets...
which is written by Kristina Chodorow.
When added safe option, it was going to the error condition and prints
the following error couple of times then hangs.
Got Error >>>>can't get db response, not connected at /usr/lib/perl5/
site_perl/5.8.5/i386-linux-thread-multi/MongoDB/Cursor.pm line 260.
Got Error >>>>can't get db response, not connected at /usr/lib/perl5/
site_perl/5.8.5/i386-linux-thread-multi/MongoDB/Cursor.pm line 260.
Any idea why? Any help is appreciated.
The script is
use strict;
use warnings;
use MongoDB;
my @mongo_cluster = ('mongo01:27017','mongo02:27017','mongo03:27017');
my $conn_str = "mongodb://".join(',', @mongo_cluster);
my $m = MongoDB::Connection->new( host => $conn_str, find_master =>
1,);
my $c = $m->foo->bar;
while (1) {
eval {
$c->insert( {num => 2 })
};
if ($@) {
print "Got Error >>>>$@";
}
else {
if ($m->_master){
print "connected to: ".$m->_master->{host}."\n";
}
else {
print "no master\n";
}
}
sleep 1;