我正在尝试将Official C driver
与mongoLab
对接,但会收到failed to authenticate credentials
的错误。有没有人有关于如何使用mongolab
连接C driver
的简单示例。这是我的示例代码
const char* String_uri = "mongodb://<username>:<pwd>@ds011115.mongolab.com:11115/tempdb";
uri = mongoc_uri_new(String_uri);
client = mongoc_client_new_from_uri (uri);
collection = mongoc_client_get_collection (client, "mydb", "mycoll");
doc = bson_new_from_json ((const uint8_t *)"{\"hello\" : \"world\"}", -1, &error);
count = mongoc_collection_count (collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error);
if (count < 0) {
fprintf (stderr, "%s\n", error.message);
} else {
printf ("%" PRId64 "\n", count);
}