在C ++ R3.0.2驱动程序中使用连接池连接到MongoDB副本集的正确方法是什么?

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

本文关键字:连接 副本 MongoDB 是什么 方法 R3 驱动程序      更新时间:2023-10-16

我正在升级我的mongodb c++客户端代码从传统驱动程序和26compat驱动程序到r3.0.2驱动程序。scoped连接池类现在被删除了。我的问题是如何连接到副本集与连接池。我现在的代码是:

 //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}};

使用默认的最大池大小100值。但我不知道我的方式是否正确?

您将需要使用mongocxx::pool类。URI看起来很好—只要您有replicaSet选项,驱动程序就可以理解以复制集模式连接。