[英]mongodb c++ driver authenticate
I use ScopedDbConnection, it made in each db operation. 我使用ScopedDbConnection,它在每个数据库操作中进行。 If I do:
如果我做:
mongo::ScopedDbConnection conn(host);
conn->auth(BSON("user"<<"user1"<<"pwd"<<"password1"));
...
conn.done();
That means there will involve auth process in every db operation, this is unnecessary. 这意味着在每个数据库操作中都将涉及认证过程,这是不必要的。 In java driver, there is DB class which has a authenticate function, after "db.authenticate(...)", all subsequent operation can be execute rather than auth on each db connection like above code.
在Java驱动程序中,有一个具有验证功能的数据库类,在“ db.authenticate(...)”之后,可以对每个数据库连接执行所有后续操作,而不是对auth进行验证,如上面的代码。
Is there way to just auth once in C++ driver? 有没有办法只在C ++驱动程序中进行一次身份验证?
Consider the following solution: 考虑以下解决方案:
conn_ = new DBClientReplicaSet(...);
conn_->connect();
conn_->auth(BSON("user" << "xxx" << "password" << "xxx"));
Then you can use conn_ to do any database operation. 然后,您可以使用conn_进行任何数据库操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.