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:
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: {"...
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.
On Friday, October 26, 2012 5:27:33 PM UTC-4, gli wrote:
> 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:
> 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: {"...
> 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.
On Friday, October 26, 2012 5:27:33 PM UTC-4, gli wrote:
> 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:
> 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: {"...
> 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.
On Thursday, November 1, 2012 11:28:38 AM UTC-5, Dwight Merriman wrote: > i don't know the exact answer but it looks like you are not getting a > DBClientReplicaSet object but rather the syncclusterconnection thing.
> 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...
> On Friday, October 26, 2012 5:27:33 PM UTC-4, gli wrote:
>> 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:
>> 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: {"...
>> 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.