1MONGOC_COLLECTION_DROP_WITH_OPTS(3)libmongocMONGOC_COLLECTION_DROP_WITH_OPTS(3)
2
3
4

NAME

6       mongoc_collection_drop_with_opts - mongoc_collection_drop_with_opts()
7

SYNOPSIS

9          bool
10          mongoc_collection_drop_with_opts (mongoc_collection_t *collection,
11                                            bson_t *opts,
12                                            bson_error_t *error);
13

PARAMETERS

15collection: A mongoc_collection_t.
16
17error: An optional location for a bson_error_t or NULL.
18
19       opts may be NULL or a BSON document with additional command options:
20
21writeConcern:    Construct    a    mongoc_write_concern_t   and   use
22         mongoc_write_concern_append() to add the write concern to  opts.  See
23         the example code for mongoc_client_write_command_with_opts().
24
25sessionId:    First,   construct   a   mongoc_client_session_t   with
26         mongoc_client_start_session().  You  can  begin  a  transaction  with
27         mongoc_client_session_start_transaction(),    optionally    with    a
28         mongoc_transaction_opt_t that overrides the  options  inherited  from
29         collection, and use mongoc_client_session_append() to add the session
30         to opts. See the example code for mongoc_client_session_t.
31
32collation: Configure textual comparisons. See Setting  Collation  Or‐
33         der,  and  the  MongoDB Manual entry on Collation. Collation requires
34         MongoDB 3.2 or later, otherwise an error is returned.
35
36serverId: To target a specific server, include  an  int32  "serverId"
37         field.  Obtain  the id by calling mongoc_client_select_server(), then
38         mongoc_server_description_id() on its return value.
39

DESCRIPTION

41       This function requests that a collection be dropped, including all  in‐
42       dexes associated with the collection.
43
44       If no write concern is provided in opts, the collection's write concern
45       is used.
46
47       If the collection does not exist, the server responds with an  "ns  not
48       found"  error.  It is safe to ignore this error; set the Error API Ver‐
49       sion to 2 and ignore server error code 26:
50
51          mongoc_client_t *client;
52          mongoc_collection_t *collection;
53          bson_error_t error;
54          bool r;
55
56          client = mongoc_client_new (NULL);
57          mongoc_client_set_error_api (client, 2);
58          collection = mongoc_client_get_collection (client, "db", "collection");
59          r = mongoc_collection_drop_with_opts (collection, NULL /* opts */, &error);
60          if (r) {
61             printf ("Dropped.\n");
62          } else {
63             printf ("Error message: %s\n", error.message);
64             if (error.domain == MONGOC_ERROR_SERVER && error.code == 26) {
65                printf ("Ignoring 'ns not found' error\n");
66             } else {
67                fprintf (stderr, "Unrecognized error!\n");
68             }
69          }
70
71          mongoc_collection_destroy (collection);
72          mongoc_client_destroy (client);
73
74       In MongoDB 3.0 and older, the "ns not found" error code is the  generic
75       MONGOC_ERROR_QUERY_FAILURE;  in  this case check whether the error mes‐
76       sage is equal to the string "ns not found".
77
78       The encryptedFields document in opts may be used to drop  a  collection
79       for  Queryable Encryption. If encryptedFields is specified, the "ns not
80       found" error is not returned.
81

ERRORS

83       Errors are propagated via the error parameter.
84

RETURNS

86       Returns true if the collection was successfully dropped. Returns  false
87       and  sets  error  if there are invalid arguments or a server or network
88       error.
89

AUTHOR

91       MongoDB, Inc
92
94       2017-present, MongoDB, Inc
95
96
97
98
991.24.3                           Aug 17, 202M3ONGOC_COLLECTION_DROP_WITH_OPTS(3)
Impressum