@@ -1278,7 +1278,8 @@ cursor collection::list_indexes(const client_session& session) const {
1278
1278
}
1279
1279
1280
1280
void collection::_drop (const client_session* session,
1281
- const stdx::optional<mongocxx::write_concern>& wc) {
1281
+ const stdx::optional<mongocxx::write_concern>& wc,
1282
+ bsoncxx::document::view_or_value collection_options) {
1282
1283
bson_error_t error;
1283
1284
1284
1285
bsoncxx::builder::basic::document opts_doc;
@@ -1290,6 +1291,10 @@ void collection::_drop(const client_session* session,
1290
1291
opts_doc.append (bsoncxx::builder::concatenate_doc{session->_get_impl ().to_document ()});
1291
1292
}
1292
1293
1294
+ if (!collection_options.view ().empty ()) {
1295
+ opts_doc.append (bsoncxx::builder::concatenate_doc{collection_options});
1296
+ }
1297
+
1293
1298
scoped_bson_t opts_bson{opts_doc.view ()};
1294
1299
auto result =
1295
1300
libmongoc::collection_drop_with_opts (_get_impl ().collection_t , opts_bson.bson (), &error);
@@ -1304,35 +1309,22 @@ void collection::_drop(const client_session* session,
1304
1309
}
1305
1310
1306
1311
void collection::drop (const stdx::optional<mongocxx::write_concern>& wc) {
1307
- return _drop (nullptr , wc);
1312
+ return _drop (nullptr , wc, {} );
1308
1313
}
1309
1314
1310
1315
void collection::drop (const client_session& session,
1311
1316
const stdx::optional<mongocxx::write_concern>& wc) {
1312
- return _drop (&session, wc);
1317
+ return _drop (&session, wc, {} );
1313
1318
}
1314
1319
1315
- // TODO: This was needed to get FLE 2 spec tests to pass.
1316
- // Should we allow users to specify options, or should there be a specialized
1317
- // drop for specifying encrypted fields?
1320
+ // From the spec:
1321
+ // https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.rst#user-facing-api
1322
+ // > Drivers MUST support a BSON document option named encryptedFields for any
1323
+ // > drop command helpers (e.g. Database.dropCollection(), Collection.drop()).
1324
+ // > This option will only be interpreted by the helper method and MUST NOT be
1325
+ // > passed to the drop command.
1318
1326
void collection::drop (bsoncxx::document::view_or_value collection_options) {
1319
- bson_error_t error;
1320
-
1321
- bsoncxx::builder::basic::document opts_doc;
1322
-
1323
- opts_doc.append (bsoncxx::builder::concatenate_doc{collection_options});
1324
-
1325
- scoped_bson_t opts_bson{opts_doc.view ()};
1326
- auto result =
1327
- libmongoc::collection_drop_with_opts (_get_impl ().collection_t , opts_bson.bson (), &error);
1328
-
1329
- // Throw an exception if the command failed, unless the failure was due to a non-existent
1330
- // collection. We check for this failure using 'code', but we fall back to checking 'message'
1331
- // for old server versions (3.0 and earlier) that do not send a code with the command response.
1332
- if (!result && !(error.code == ::MONGOC_ERROR_COLLECTION_DOES_NOT_EXIST ||
1333
- stdx::string_view{error.message } == stdx::string_view{" ns not found" })) {
1334
- throw_exception<operation_exception>(error);
1335
- }
1327
+ return _drop (nullptr , {}, collection_options);
1336
1328
}
1337
1329
1338
1330
void collection::read_concern (class read_concern rc) {
0 commit comments