1MONGOC_CLIENT_GET_DEFAULT_DATABASE(3l)ibmongMoOcNGOC_CLIENT_GET_DEFAULT_DATABASE(3)
2
3
4
6 mongoc_client_get_default_database - mongoc_client_get_default_data‐
7 base()
8
10 mongoc_database_t *
11 mongoc_client_get_default_database (mongoc_client_t *client)
12 BSON_GNUC_WARN_UNUSED_RESULT;
13
14 Get the database named in the MongoDB connection URI, or NULL if the
15 URI specifies none.
16
17 Useful when you want to choose which database to use based only on the
18 URI in a configuration file.
19
21 • client: A mongoc_client_t.
22
24 A newly allocated mongoc_database_t that should be freed with mon‐
25 goc_database_destroy().
26
28 Default Database Example
29
30 /* default database is "db_name" */
31 mongoc_client_t *client = mongoc_client_new ("mongodb://host/db_name");
32 mongoc_database_t *db = mongoc_client_get_default_database (client);
33
34 assert (!strcmp ("db_name", mongoc_database_get_name (db)));
35
36 mongoc_database_destroy (db);
37 mongoc_client_destroy (client);
38
39 /* no default database */
40 client = mongoc_client_new ("mongodb://host/");
41 db = mongoc_client_get_default_database (client);
42
43 assert (!db);
44
45 mongoc_client_destroy (client);
46
48 MongoDB, Inc
49
51 2017-present, MongoDB, Inc
52
53
54
55
561.20.0 Nov 18, 2M0O2N1GOC_CLIENT_GET_DEFAULT_DATABASE(3)