1

I've created a client that needs to read and process data from the database.

I've realised that I can't test the connection I create with mongoc_client_new by just testing if that is null, because the driver uses lazy connections.

How do I test if the database is actually up and running then? Maybe searching the database with no query criteria added?

I tried get_collection_count but that spits out -1 whether the database is running or not.

Stennie
  • 63,885
  • 14
  • 149
  • 175
FreakShow
  • 57
  • 7

1 Answers1

2

I assume mongoc_client_get_server_status can give the info.

      bson_t reply;
      bson_error_t error;
      if(mongoc_client_get_server_status(client, nullptr, &reply, &error)) {
        bson_iter_t iter;
        assert(bson_iter_init_find (&iter, &reply, "ok"));
      }
      bson_destroy(&reply);
Totonga
  • 4,236
  • 2
  • 25
  • 31