1MONGOC_DATABASE_GET_COLLECTIONM_ONNAGMOECSl__iDWbAImTToAHnB_gAOoSPcET_SG(E3T)_COLLECTION_NAMES_WITH_OPTS(3)
2
3
4
6 mongoc_database_get_collection_names_with_opts - mongoc_data‐
7 base_get_collection_names_with_opts()
8
10 char **
11 mongoc_database_get_collection_names_with_opts (mongoc_database_t *database,
12 const bson_t *opts,
13 bson_error_t *error);
14
15 Fetches a NULL terminated array of NULL-byte terminated char* strings
16 containing the names of all of the collections in database.
17
18 This function is considered a retryable read operation. Upon a tran‐
19 sient error (a network error, errors due to replica set failover, etc.)
20 the operation is safely retried once. If retryreads is false in the
21 URI (see mongoc_uri_t) the retry behavior does not apply.
22
24 · database: A mongoc_database_t.
25
26 · opts: A bson_t containing additional options.
27
28 · error: An optional location for a bson_error_t or NULL.
29
30 opts may be NULL or a BSON document with additional command options:
31
32 · sessionId: First, construct a mongoc_client_session_t with mon‐
33 goc_client_start_session. You can begin a transaction with mon‐
34 goc_client_session_start_transaction, optionally with a mongoc_trans‐
35 action_opt_t that overrides the options inherited from database, and
36 use mongoc_client_session_append to add the session to opts. See the
37 example code for mongoc_client_session_t.
38
39 · serverId: To target a specific server, include an int32 "serverId"
40 field. Obtain the id by calling mongoc_client_select_server, then
41 mongoc_server_description_id on its return value.
42
43 For a list of all options, see the MongoDB Manual entry on the listCol‐
44 lections command.
45
47 Errors are propagated via the error parameter.
48
50 A NULL terminated array of NULL terminated char* strings that should be
51 freed with bson_strfreev(). Upon failure, NULL is returned and error is
52 set.
53
55 {
56 bson_t opts = BSON_INITIALIZER;
57 mongoc_read_concern_t *rc;
58 bson_error_t error;
59 char **strv;
60 unsigned i;
61
62 rc = mongoc_read_concern_new ();
63 mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_MAJORITY);
64 mongoc_read_concern_append (rc, &opts);
65 if ((strv = mongoc_database_get_collection_names_with_opts (
66 database, &opts, &error))) {
67
68 for (i = 0; strv[i]; i++)
69 printf ("%s\n", strv[i]);
70
71 bson_strfreev (strv);
72 } else {
73 fprintf (stderr, "Command failed: %s\n", error.message);
74 }
75
76 mongoc_read_concern_destroy (rc);
77 bson_destroy (&opts);
78 }
79
81 MongoDB, Inc
82
84 2017-present, MongoDB, Inc
85
86
87
88
891.16.2 MONGFOeCb_D2A5T,AB2A0S2E0_GET_COLLECTION_NAMES_WITH_OPTS(3)