1MONGOC_CLIENT_GET_DEFAULT_DATABASE(3l)ibmongMoOcNGOC_CLIENT_GET_DEFAULT_DATABASE(3)
2
3
4

NAME

6       mongoc_client_get_default_database   -  mongoc_client_get_default_data‐
7       base()
8

SYNOPSIS

10          mongoc_database_t *
11          mongoc_client_get_default_database (mongoc_client_t *client);
12
13       Get the database named in the MongoDB connection URI, or  NULL  if  the
14       URI specifies none.
15
16       Useful  when you want to choose which database to use based only on the
17       URI in a configuration file.
18

PARAMETERS

20       · client: A mongoc_client_t.
21

RETURNS

23       A newly allocated mongoc_database_t that  should  be  freed  with  mon‐
24       goc_database_destroy().
25

EXAMPLE

27       Default Database Example.INDENT 0.0
28
29          /* default database is "db_name" */
30          mongoc_client_t *client = mongoc_client_new ("mongodb://host/db_name");
31          mongoc_database_t *db = mongoc_client_get_default_database (client);
32
33          assert (!strcmp ("db_name", mongoc_database_get_name (db)));
34
35          mongoc_database_destroy (db);
36          mongoc_client_destroy (client);
37
38          /* no default database */
39          client = mongoc_client_new ("mongodb://host/");
40          db = mongoc_client_get_default_database (client);
41
42          assert (!db);
43
44          mongoc_client_destroy (client);
45

AUTHOR

47       MongoDB, Inc
48
50       2017-present, MongoDB, Inc
51
52
53
54
551.16.2                           Feb 25, 2M0O2N0GOC_CLIENT_GET_DEFAULT_DATABASE(3)
Impressum