diff options
author | Louis Williams <louis.williams@mongodb.com> | 2020-06-16 12:42:46 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-06-16 19:47:17 +0000 |
commit | b9874b9c81e529e661b6615dd2ce5948e6db15bc (patch) | |
tree | 93f386b9730749d9963c178c852bd33c683777c2 | |
parent | 5ef9529c441df3e4106845e698a3000f70073cb9 (diff) | |
download | mongo-b9874b9c81e529e661b6615dd2ce5948e6db15bc.tar.gz |
SERVER-48891 reIndex should not lookup nonexistent database in ViewCatalog
-rw-r--r-- | jstests/replsets/reindex.js | 4 | ||||
-rw-r--r-- | src/mongo/db/commands/drop_indexes.cpp | 3 |
2 files changed, 6 insertions, 1 deletions
diff --git a/jstests/replsets/reindex.js b/jstests/replsets/reindex.js index a687bc4fb57..316e5cd7f1e 100644 --- a/jstests/replsets/reindex.js +++ b/jstests/replsets/reindex.js @@ -64,6 +64,10 @@ assert.eq(2, testColl.getIndexes().length, "Standalone didn't have proper indexe assert.commandWorked(testColl.reIndex()); +const nonExistentDb = standalone.getDB('does_not_exist'); +assert.commandFailedWithCode(nonExistentDb.getCollection('test').reIndex(), + ErrorCodes.NamespaceNotFound); + assert.eq(2, testColl.getIndexes().length, "Standalone didn't have proper indexes after reindex"); MongoRunner.stopMongod(standalone); diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index 78e7413c00b..19eb43b32fa 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -143,7 +143,8 @@ public: AutoGetCollection autoColl(opCtx, toReIndexNss, MODE_X); Collection* collection = autoColl.getCollection(); if (!collection) { - if (ViewCatalog::get(autoColl.getDb())->lookup(opCtx, toReIndexNss.ns())) + auto db = autoColl.getDb(); + if (db && ViewCatalog::get(db)->lookup(opCtx, toReIndexNss.ns())) uasserted(ErrorCodes::CommandNotSupportedOnView, "can't re-index a view"); else uasserted(ErrorCodes::NamespaceNotFound, "collection does not exist"); |