我似乎无法从C驱动程序中找到有关mongodb身份验证的文档。据我所知,C驱动程序API没有关于它的信息。但是,this link让我觉得这是可能的。链接或代码段会很棒。谢谢!
答案 0 :(得分:2)
这是要调用的函数。
MONGO_EXPORT int mongo_cmd_authenticate (
mongo * conn,
const char * db,
const char * user,
const char * pass
)
Authenticate a user.
Parameters:
conn a mongo object.
db the database to authenticate against.
user the user name to authenticate.
pass the user's password.
Returns:
MONGO_OK on sucess and MONGO_ERROR on failure.
以下是测试代码的摘录作为示例 - mongo-c-driver / test / auth_test.c
if ( mongo_connect( conn , TEST_SERVER, 27017 ) ) {
printf( "failed to connect\n" );
exit( 1 );
}
ASSERT( mongo_cmd_authenticate( conn, db, "user", "password" ) == MONGO_OK );
...
希望这会有所帮助。以下是一些有关进一步信息的链接。
参考文献:
MongoDB C语言中心 - http://www.mongodb.org/display/DOCS/C+Language+Center
MongoDB C驱动程序文档 - http://api.mongodb.org/c/current/
MongoDB C驱动程序API文档 - http://api.mongodb.org/c/current/api/index.html
mongo.h文件参考 - http://api.mongodb.org/c/current/api/mongo_8h.html
mongo_cmd_authenticate - http://api.mongodb.org/c/current/api/mongo_8h.html#a715aaa6b82e23486e6caad2b544f2ebf
MongoDB C驱动程序源代码 - https://github.com/mongodb/mongo-c-driver
test / auth_test.c - https://github.com/mongodb/mongo-c-driver/blob/master/test/auth_test.c