1MONGOC_DATABASE_FIND_COLLECTIONS_WMIOTlNHiG_bOOmCPo_TnDSgA(oT3cA)BASE_FIND_COLLECTIONS_WITH_OPTS(3)
2
3
4

NAME

6       mongoc_database_find_collections_with_opts  - mongoc_database_find_col‐
7       lections_with_opts()
8

SYNOPSIS

10          mongoc_cursor_t *
11          mongoc_database_find_collections_with_opts (mongoc_database_t *database,
12                                                      const bson_t *opts)
13             BSON_GNUC_WARN_UNUSED_RESULT;
14
15       Fetches a cursor containing documents, each corresponding to a  collec‐
16       tion on this database.
17
18       To         get         collection         names        only,        use
19       mongoc_database_get_collection_names_with_opts().
20
21       This function is considered a retryable read operation.  Upon  a  tran‐
22       sient error (a network error, errors due to replica set failover, etc.)
23       the operation is safely retried once.  If retryreads is  false  in  the
24       URI (see mongoc_uri_t) the retry behavior does not apply.
25

PARAMETERS

27database: A mongoc_database_t.
28
29opts: A bson_t containing additional options.
30
31       opts may be NULL or a BSON document with additional command options:
32
33sessionId:    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
40serverId: 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

ERRORS

48       Use mongoc_cursor_error() on the returned cursor to check for errors.
49

RETURNS

51       This  function returns a newly allocated mongoc_cursor_t that should be
52       freed with mongoc_cursor_destroy() when no longer in use. The  returned
53       mongoc_cursor_t  is  never  NULL,  even  on  error.  The user must call
54       mongoc_cursor_next() on the returned  mongoc_cursor_t  to  execute  the
55       initial command.
56
57       Cursor  errors  can  be checked with mongoc_cursor_error_document(). It
58       always fills out the bson_error_t if an error occurred, and  optionally
59       includes a server reply document if the error occurred server-side.
60
61       WARNING:
62          Failure  to  handle the result of this function is a programming er‐
63          ror.
64
65       In the returned cursor each result corresponds to the  server's  repre‐
66       sentation of a collection in this database.
67
68       The         cursor         functions         mongoc_cursor_set_limit(),
69       mongoc_cursor_set_batch_size(),                                     and
70       mongoc_cursor_set_max_await_time_ms()  have no use on the returned cur‐
71       sor.
72

EXAMPLES

74          {
75             bson_t opts = BSON_INITIALIZER;
76             bson_t name_filter;
77             const bson_t *doc;
78             bson_iter_t iter;
79             bson_error_t error;
80             mongoc_cursor_t *cursor;
81
82             BSON_APPEND_DOCUMENT_BEGIN (&opts, "filter", &name_filter);
83             /* find collections with names like "abbbbc" */
84             BSON_APPEND_REGEX (&name_filter, "name", "ab+c", NULL);
85             bson_append_document_end (&opts, &name_filter);
86
87             cursor = mongoc_database_find_collections_with_opts (database, &opts);
88             while (mongoc_cursor_next (cursor, &doc)) {
89                bson_iter_init_find (&iter, doc, "name");
90                printf ("found collection: %s\n", bson_iter_utf8 (&iter, NULL));
91             }
92
93             if (mongoc_cursor_error (cursor, &error)) {
94                fprintf (stderr, "%s\n", error.message);
95             }
96
97             mongoc_cursor_destroy (cursor);
98             bson_destroy (&opts);
99          }
100
101       SEE ALSO:
102          mongoc_database_get_collection_names_with_opts()
103
104

AUTHOR

106       MongoDB, Inc
107
109       2017-present, MongoDB, Inc
110
111
112
113
1141.24.3                           AMuOgNG1O7C,_D2A0T2A3BASE_FIND_COLLECTIONS_WITH_OPTS(3)
Impressum