summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/drop_indexes.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2018-11-08 15:51:21 -0500
committerBenety Goh <benety@mongodb.com>2018-11-08 15:51:21 -0500
commit66ed8cbe8277e63d5c908b68ba8721af23390d1a (patch)
tree8ce2131186f2634e28aef8bb6ca59edf7c81fbc3 /src/mongo/db/catalog/drop_indexes.cpp
parentc9ba97851eb8dc39f5f2bc5626d08e0f1d099cca (diff)
downloadmongo-66ed8cbe8277e63d5c908b68ba8721af23390d1a.tar.gz
SERVER-37727 dropIndexes supports dropping multiple indexes
Diffstat (limited to 'src/mongo/db/catalog/drop_indexes.cpp')
-rw-r--r--src/mongo/db/catalog/drop_indexes.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp
index 6b976b83892..2c25819720b 100644
--- a/src/mongo/db/catalog/drop_indexes.cpp
+++ b/src/mongo/db/catalog/drop_indexes.cpp
@@ -54,6 +54,7 @@ namespace {
// 1) '*' - drop all indexes.
// 2) <index name> - name of single index to drop.
// 3) <index key pattern> - BSON document representing key pattern of index to drop.
+// 4) [<index name 1>, <index name 2>, ...] - array containing names of indexes to drop.
constexpr auto kIndexFieldName = "index"_sd;
/**
@@ -159,6 +160,35 @@ Status wrappedRun(OperationContext* opCtx,
return Status::OK();
}
+ // The 'index' field contains a list of names of indexes to drop.
+ // Drops all or none of the indexes due to the enclosing WriteUnitOfWork.
+ if (indexElem.type() == Array) {
+ for (auto indexNameElem : indexElem.Array()) {
+ if (indexNameElem.type() != String) {
+ return Status(ErrorCodes::TypeMismatch,
+ str::stream() << "dropIndexes " << collection->ns().ns() << " ("
+ << collection->uuid()
+ << ") failed to drop multiple indexes "
+ << indexElem.toString(false)
+ << ": index name must be a string");
+ }
+
+ auto indexToDelete = indexNameElem.String();
+ auto status = dropIndexByName(opCtx, collection, indexCatalog, indexToDelete);
+ if (!status.isOK()) {
+ return status.withContext(str::stream() << "dropIndexes " << collection->ns().ns()
+ << " ("
+ << collection->uuid()
+ << ") failed to drop multiple indexes "
+ << indexElem.toString(false)
+ << ": "
+ << indexToDelete);
+ }
+ }
+
+ return Status::OK();
+ }
+
return Status(ErrorCodes::IndexNotFound,
str::stream() << "invalid index name spec: " << indexElem.toString(false));
}