Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
c++ driver: DBClientReplicaSet insert() Throws Exceptions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
gli  
View profile  
 More options Oct 26 2012, 5:27 pm
From: gli <guogangl...@gmail.com>
Date: Fri, 26 Oct 2012 14:27:33 -0700 (PDT)
Local: Fri, Oct 26 2012 5:27 pm
Subject: c++ driver: DBClientReplicaSet insert() Throws Exceptions

Hi,

I used the rs command in mongo command shell and created a replica set,
with 3 members. rs.status() command shows the 3 members, with one "PRIMARY"
and the rest two "SECONDARY". All the "health" flags are 1.

I followed the mongo-cxx-driver-v2.2/src/mongo/client/examples/rs.cpp, and
wrote a mongo client replica program. The following code calls the
connect(), and it works:

string errmsg;
ConnectionString cs = ConnectionString::parse(
"server1:27017,server2:27017, server3:27017" , errmsg );

DBClientReplicaSet * conn = static_cast<DBClientReplicaSet*>( cs.connect(
errmsg, 30 ) );

The c++ driver outputs the following messages to stdout, after the
connect() call:

Fri Oct 26 13:05:12 SyncClusterConnection connecting to [server1:27017]
Fri Oct 26 13:05:13 SyncClusterConnection connecting to [server2:27017]
Fri Oct 26 13:05:13 SyncClusterConnection connecting to [server3:27017]

However, the insert() throws exception, with the text of
"SyncClusterConnection::insert obj has to have an _id: {"...

This is how a BSONObj is built:

mongo::BSONObjBuilder builder;
builder.append("tranname", value1);
builder.append("tranid", value2);
builder.append("time", value3);
builder.append("xml", value4);

mongo::BSONObj bson = builder.obj();
conn->insert("collection_name", bson);
I guess the problem is the way how BSONObj is built for DBClientReplicaSet.
The BSONObj built works for DBClientConnection.

Could anyone please shed the light?

Thanks for your help.

gli


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dwight Merriman  
View profile  
 More options Nov 1 2012, 12:28 pm
From: Dwight Merriman <dwi...@10gen.com>
Date: Thu, 1 Nov 2012 09:28:38 -0700 (PDT)
Local: Thurs, Nov 1 2012 12:28 pm
Subject: Re: c++ driver: DBClientReplicaSet insert() Throws Exceptions

i don't know the exact answer but it looks like you are not getting a
DBClientReplicaSet object but rather the syncclusterconnection thing.

perhaps instantiates directly? ie:

 DBClientReplicaSet * set = new DBClientReplicaSet( _setName , _servers ,
socketTimeout );
            if( ! set->connect() ) {
                delete set;
                errmsg = "connect failed to set ";
                errmsg += toString();
                return 0;
            }
            return set;

see client/dbclient.cpp for more details including the parse() method
source.

p.s. without diving deeper i don't know why it does that but it does...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dwight Merriman  
View profile  
 More options Nov 1 2012, 12:30 pm
From: Dwight Merriman <dwi...@10gen.com>
Date: Thu, 1 Nov 2012 09:30:58 -0700 (PDT)
Local: Thurs, Nov 1 2012 12:30 pm
Subject: Re: c++ driver: DBClientReplicaSet insert() Throws Exceptions

i think i see now

you need <setname>/<hostseedlist>

so you need something like

  ConnectionString cs = ConnectionString::parse(
"MYSETNAME/server1:27017,server2:27017, server3:27017" , errmsg );
 see comment in dbclientinterface.h


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gli  
View profile  
 More options Nov 2 2012, 11:47 am
From: gli <guogangl...@gmail.com>
Date: Fri, 2 Nov 2012 08:47:01 -0700 (PDT)
Local: Fri, Nov 2 2012 11:47 am
Subject: Re: c++ driver: DBClientReplicaSet insert() Throws Exceptions

Hi Dwight,

Thanks a lot for pointing out the code in mongo/client/dbclient.cpp. This
is exact call I'm looking for.

I'll give it a try.

GLI


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »