Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5358693
  • 博文数量: 1144
  • 博客积分: 11974
  • 博客等级: 上将
  • 技术积分: 12312
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-13 20:06
文章存档

2017年(2)

2016年(14)

2015年(10)

2014年(28)

2013年(23)

2012年(29)

2011年(53)

2010年(86)

2009年(83)

2008年(43)

2007年(153)

2006年(575)

2005年(45)

分类: LINUX

2011-12-08 20:39:48

Hi Mongos,

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;

阅读(1178) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~