c - mongodb C 驱动认证

标签 c authentication mongodb

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

最佳答案

这是要调用的函数。

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

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

关于c - mongodb C 驱动认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11253337/

相关文章:

.net - 使用Web场进行身份验证

javascript - 在集合中搜索游标的元素

java - mongodb性能不佳

c - strcpy 从一个字符串数组到另一个字符串数组

c++ - 仅在 NDK 中传递给 c 编译器的标志

c - wcsncpy 和 wcscpy_s 有什么区别?

php - 当我尝试在真实设备上运行登录 Activity 时出错(在模拟器上运行完美)

ios - 解析当前用户在应用程序删除后仍然存在,但不保留实际用户

c - 有人会如何在 USB 上安装和编译 gcc C

node.js - 如何使用 { $text : { $search: search } } within sails-mongodb?