mongo-cxx-driver-legacy-1.0.4
scons --extrapath=/usr/local/boost158/ --prefix=/usr/local/mongodb30 --ssl=SSL --use-sasl-client=USE-SASL-CLIENT ./
boost_1_58_0.tar
./bootstrap.sh --prefix=/usr/local/boost158
./b2 install
mongo-cxx-pool-master(需要-std=c++11 可以修改源码用低版本编译)
mongodb3.0 连接串mongodb://xxx:[email protected]:27017/admin
mongodb3.0 复制集连接串mongodb://xxx:[email protected]:27011,192.168.0.21:27012,192.168.0.21:27010/admin?authMechanism=SCRAM-SHA-1&authSource=admin&replicaSet=rs0(使用authMechanism= MONGODB-CR失败 默认)
需要先认证才能准确得到 mastr和slave
cout<<"11:"<<conn->slaveConn().getServerAddress()<<endl;
BSONObj obj = conn->slaveConn().findOne("test.testdb", MONGO_QUERY("_id"<<OID("55b886c1b0852f7c713227b0")),0,QueryOption_SlaveOk);
cout<<obj.jsonString()<<endl;
可能获取不同的地址
DBClientConnection& conn1 = conn->slaveConn();
cout<<"11:"<<conn1.getServerAddress()<<endl;
BSONObj obj = conn1.findOne("test.testdb", MONGO_QUERY("_id"<<OID("55b886c1b0852f7c713227b0")),0,QueryOption_SlaveOk);
cout<<obj.jsonString()<<endl;