1MONGOC_COLLECTION_DROP_WITH_OPTS(3)libmongocMONGOC_COLLECTION_DROP_WITH_OPTS(3)
2
3
4
6 bool
7 mongoc_collection_drop_with_opts (mongoc_collection_t *collection,
8 bson_t *opts,
9 bson_error_t *error);
10
12 • collection: A mongoc_collection_t.
13
14 • error: An optional location for a bson_error_t or NULL.
15
16 opts may be NULL or a BSON document with additional command options:
17
18 • writeConcern: Construct a mongoc_write_concern_t and use
19 mongoc_write_concern_append() to add the write concern to opts. See
20 the example code for mongoc_client_write_command_with_opts().
21
22 • sessionId: First, construct a mongoc_client_session_t with
23 mongoc_client_start_session(). You can begin a transaction with
24 mongoc_client_session_start_transaction(), optionally with a
25 mongoc_transaction_opt_t that overrides the options inherited from
26 collection, and use mongoc_client_session_append() to add the session
27 to opts. See the example code for mongoc_client_session_t.
28
29 • collation: Configure textual comparisons. See Setting Collation Or‐
30 der, and the MongoDB Manual entry on Collation. Collation requires
31 MongoDB 3.2 or later, otherwise an error is returned.
32
33 • serverId: To target a specific server, include an int32 "serverId"
34 field. Obtain the id by calling mongoc_client_select_server(), then
35 mongoc_server_description_id() on its return value.
36
38 This function requests that a collection be dropped, including all in‐
39 dexes associated with the collection.
40
41 If no write concern is provided in opts, the collection's write concern
42 is used.
43
44 If the collection does not exist, the server responds with an "ns not
45 found" error. It is safe to ignore this error; set the Error API Ver‐
46 sion to 2 and ignore server error code 26:
47
48 mongoc_client_t *client;
49 mongoc_collection_t *collection;
50 bson_error_t error;
51 bool r;
52
53 client = mongoc_client_new (NULL);
54 mongoc_client_set_error_api (client, 2);
55 collection = mongoc_client_get_collection (client, "db", "collection");
56 r = mongoc_collection_drop_with_opts (collection, NULL /* opts */, &error);
57 if (r) {
58 printf ("Dropped.\n");
59 } else {
60 printf ("Error message: %s\n", error.message);
61 if (error.domain == MONGOC_ERROR_SERVER && error.code == 26) {
62 printf ("Ignoring 'ns not found' error\n");
63 } else {
64 fprintf (stderr, "Unrecognized error!\n");
65 }
66 }
67
68 mongoc_collection_destroy (collection);
69 mongoc_client_destroy (client);
70
71 In MongoDB 3.0 and older, the "ns not found" error code is the generic
72 MONGOC_ERROR_QUERY_FAILURE; in this case check whether the error mes‐
73 sage is equal to the string "ns not found".
74
75 The encryptedFields document in opts may be used to drop a collection
76 for Queryable Encryption. If encryptedFields is specified, the "ns not
77 found" error is not returned.
78
80 Errors are propagated via the error parameter.
81
83 Returns true if the collection was successfully dropped. Returns false
84 and sets error if there are invalid arguments or a server or network
85 error.
86
88 MongoDB, Inc
89
91 2017-present, MongoDB, Inc
92
93
94
95
961.25.1 Nov 08, 202M3ONGOC_COLLECTION_DROP_WITH_OPTS(3)