Dean Chen Dean Chen - 7 months ago 42
C++ Question

what's the correct way to connect to mongodb replica set with connection pool in c++ r3.0.2 driver?

I am upgrading my mongodb c++ client code from legacy driver and 26compat driver to r3.0.2 driver. The scopedconnection pool class is removed now. My question is how to connect to replica set with connection pool. My current code is:

//only call it once in my app
mongocxx::instance inst{};
//call it in anywhere I need
mongocxx::client conn{mongocxx::uri{mongodb://i-e6ql0k8k,i-exiv5yox,i-sfdxzsjr/?replicaSet=rs1}};

use the default maximum pool size 100 value.
But I do not know if my way is the correct or not?

xdg xdg

You'll want to use the mongocxx::pool class. The URI looks fine – as long as you have the replicaSet option, the driver understands to connect in replica set mode.