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  mon‐
22         goc_write_concern_append to add the write concern to  opts.  See  the
23         example code for mongoc_client_write_command_with_opts.
24
25sessionId:  First,  construct  a  mongoc_client_session_t  with  mon‐
26         goc_client_start_session. You  can  begin  a  transaction  with  mon‐
27         goc_client_session_start_transaction, optionally with a mongoc_trans‐
28         action_opt_t that overrides the options  inherited  from  collection,
29         and  use mongoc_client_session_append to add the session to opts. See
30         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

ERRORS

79       Errors are propagated via the error parameter.
80

RETURNS

82       Returns true if the collection was successfully dropped. Returns  false
83       and  sets  error  if there are invalid arguments or a server or network
84       error.
85

AUTHOR

87       MongoDB, Inc
88
90       2017-present, MongoDB, Inc
91
92
93
94
951.17.6                           Jun 03, 202M1ONGOC_COLLECTION_DROP_WITH_OPTS(3)
Impressum