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