2012-06-28 71 views
1

我似乎无法从C驱动程序找到有关mongodb身份验证的文档。据我所知,C驱动程序API没有关于它的信息。然而,this link让我觉得这是可能的。链接或代码片段会很棒。谢谢!mongodb C驱动程序认证

回答

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. 

下面是测试代码的摘录为例 - 蒙戈-C驱动器/测试/ 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

测试/ auth_test.c - https://github.com/mongodb/mongo-c-driver/blob/master/test/auth_test.c