0

I am trying to interface Official C driver with mongoLab but getting error that failed to authenticate credentials. Do anyone have any simple example on how to interface mongolab using C driver. This is my example code

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);
   }
Saad Saadi
  • 1,031
  • 10
  • 26
  • `mongo ds011115.mongolab.com:11115/tempdb -u username -p pwd` could work well in the console? – zangw Feb 16 '16 at 06:52
  • Call `mongoc_init()` at the beginning of every program using the MongoDB C driver? – zangw Feb 16 '16 at 06:59
  • If you haven't already, contact MongoLab Support for assistance: support@mongolab.com – pneumee Feb 16 '16 at 17:33
  • @zangw, yes in `console` and with `java-drivers`, it's working perfectly. No w i am trying with `C-driver`. Yes i called `monogoc-init()` at the beginning. – Saad Saadi Feb 17 '16 at 03:11
  • Got the solution. I need to compile the `C-driver` using `--enable-ssl` support. Now everything working perfectly. Thanks – Saad Saadi Feb 18 '16 at 06:05

0 Answers0