mongoLab C驱动程序身份验证和基本示例

时间:2016-02-16 02:25:21

标签: c mongodb mlab mongodb-c

我正在尝试将Official C drivermongoLab对接,但会收到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);
   }

0 个答案:

没有答案