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);
Thanks for your help.
gli
ConnectionString cs = ConnectionString::parse( "MYSETNAME/server1:27017,server2:27017, server3:27017" , errmsg );