1MONGOC_DATABASE_FIND_COLLECTIONS_WMIOTlNHiG_bOOmCPo_TnDSgA(oT3cA)BASE_FIND_COLLECTIONS_WITH_OPTS(3)
2
3
4
6 mongoc_database_find_collections_with_opts - mongoc_database_find_col‐
7 lections_with_opts()
8
10 mongoc_cursor_t *
11 mongoc_database_find_collections_with_opts (mongoc_database_t *database,
12 const bson_t *opts);
13
14 Fetches a cursor containing documents, each corresponding to a collec‐
15 tion on this database.
16
17 To get collection names only, use mongoc_database_get_collec‐
18 tion_names_with_opts.
19
20 This function is considered a retryable read operation. Upon a tran‐
21 sient error (a network error, errors due to replica set failover, etc.)
22 the operation is safely retried once. If retryreads is false in the
23 URI (see mongoc_uri_t) the retry behavior does not apply.
24
26 · database: A mongoc_database_t.
27
28 · opts: A bson_t containing additional options.
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 Use mongoc_cursor_error on the returned cursor to check for errors.
48
50 A cursor where each result corresponds to the server's representation
51 of a collection in this database.
52
53 The cursor functions mongoc_cursor_set_limit, mongoc_cur‐
54 sor_set_batch_size, and mongoc_cursor_set_max_await_time_ms have no use
55 on the returned cursor.
56
58 {
59 bson_t opts = BSON_INITIALIZER;
60 bson_t name_filter;
61 const bson_t *doc;
62 bson_iter_t iter;
63 bson_error_t error;
64
65 BSON_APPEND_DOCUMENT_BEGIN (&opts, "filter", &name_filter);
66 /* find collections with names like "abbbbc" */
67 BSON_APPEND_REGEX (&name_filter, "name", "ab+c", NULL);
68 bson_append_document_end (&opts, &name_filter);
69
70 cursor = mongoc_database_find_collections_with_opts (database, &opts);
71 while (mongoc_cursor_next (cursor, &doc)) {
72 bson_iter_init_find (&iter, doc, "name");
73 printf ("found collection: %s\n", bson_iter_utf8 (&iter, NULL));
74 }
75
76 if (mongoc_cursor_error (cursor, &error))
77 fprintf (stderr, "%s\n", error.msg);
78 }
79
80 mongoc_cursor_destroy (cursor);
81 bson_destroy (&opts);
82 }
83
85 mongoc_database_get_collection_names_with_opts()
86
88 MongoDB, Inc
89
91 2017-present, MongoDB, Inc
92
93
94
95
961.17.4 FMeObNG0O4C,_D2A0T2A1BASE_FIND_COLLECTIONS_WITH_OPTS(3)