mongoc_client_get_default_database(3)

mongoc_client_get_default_database3

Usage

mongoc_database_t *
mongoc_client_get_default_database (mongoc_client_t *client);

Get the database named in the MongoDB connection URI, or NULL if the URI specifies none.

Useful when you want to choose which database to use based only on the URI in a configuration file.

Parameters

•

client: A mongoc_client_t.

Returns

A newly allocated mongoc_database_t that should be freed with mongoc_database_destroy().

Examples

Default Database Example

/* default database is "db_name" */
mongoc_client_t *client = mongoc_client_new ("mongodb://host/db_name");
mongoc_database_t *db = mongoc_client_get_default_database (client);
assert (!strcmp ("db_name", mongoc_database_get_name (db)));
mongoc_database_destroy (db);
mongoc_client_destroy (client);
/* no default database */
client = mongoc_client_new ("mongodb://host/");
db = mongoc_client_get_default_database (client);
assert (!db);
mongoc_client_destroy (client);

Releases

5 releases since Debian 9 (Stretch); the text changed 4 times.

  1. 9
  2. 10
  3. 11
  4. 12
  5. 13

Author

MongoDB, Inc

From libmongoc-doc 1.30.4-1+deb13u3 in Debian 13 (Trixie). Parsed by carta from the page's man source.