2012-06-28 72 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