diff options
-rw-r--r-- | jstests/noPassthrough/collmod_index_noop.js | 10 | ||||
-rw-r--r-- | src/mongo/db/catalog/coll_mod.cpp | 17 |
2 files changed, 8 insertions, 19 deletions
diff --git a/jstests/noPassthrough/collmod_index_noop.js b/jstests/noPassthrough/collmod_index_noop.js index 2e16352bd6e..a769b4d3630 100644 --- a/jstests/noPassthrough/collmod_index_noop.js +++ b/jstests/noPassthrough/collmod_index_noop.js @@ -140,8 +140,6 @@ if (collModIndexUniqueEnabled) { // Validate that if the 'unique' option is specified but is a no-op, the operation as a whole // will be a no-op. - assert.commandWorked(primaryDB.runCommand( - {collMod: collName, index: {keyPattern: {d: 1}, prepareUnique: true}})); result = assert.commandWorked(primaryDB.runCommand({ "collMod": primaryColl.getName(), "index": {"name": "d_1", "unique": true}, @@ -149,7 +147,6 @@ if (collModIndexUniqueEnabled) { validateResultForCollMod(result, {}); validateCollModOplogEntryCount({ "o.index.name": "d_1", - "o.index.prepareUnique": {$exists: false}, }, 0); @@ -161,8 +158,6 @@ if (collModIndexUniqueEnabled) { // Validate that if both the 'hidden' and 'unique' options are specified but the // 'hidden' and 'unique' options are no-ops, the operation as a whole will be a no-op. - assert.commandWorked(primaryDB.runCommand( - {collMod: collName, index: {keyPattern: {e: 1}, prepareUnique: true}})); result = assert.commandWorked(primaryDB.runCommand({ "collMod": primaryColl.getName(), "index": {"name": "e_1", "hidden": true, "unique": true}, @@ -170,7 +165,6 @@ if (collModIndexUniqueEnabled) { validateResultForCollMod(result, {}); validateCollModOplogEntryCount({ "o.index.name": "e_1", - "o.index.prepareUnique": {$exists: false}, }, 0); @@ -184,8 +178,6 @@ if (collModIndexUniqueEnabled) { // 'unique' option is a no-op, the operation as a whole will NOT be a no-op - instead, it will // generate an oplog entry with only 'expireAfterSeconds'. Ditto for the command result returned // to the user. - assert.commandWorked(primaryDB.runCommand( - {collMod: collName, index: {keyPattern: {f: 1}, prepareUnique: true}})); result = assert.commandWorked(primaryDB.runCommand({ "collMod": primaryColl.getName(), "index": {"name": "f_1", "expireAfterSeconds": 20, "unique": true}, @@ -209,8 +201,6 @@ if (collModIndexUniqueEnabled) { // 'hidden' and 'unique' options are no-ops, the operation as a whole will NOT be a no-op - // instead, it will generate an oplog entry with only 'expireAfterSeconds'. Ditto for the // command result returned to the user. - assert.commandWorked(primaryDB.runCommand( - {collMod: collName, index: {keyPattern: {g: 1}, prepareUnique: true}})); result = assert.commandWorked(primaryDB.runCommand({ "collMod": primaryColl.getName(), "index": {"name": "g_1", "expireAfterSeconds": 30, "hidden": true, "unique": true}, diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 747de3e044a..670dae8ef09 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -303,23 +303,22 @@ StatusWith<ParsedCollModRequest> parseCollModRequest(OperationContext* opCtx, auto indexObjForOplog = indexObj; if (cmdIndex.getUnique()) { - // Disallow one-step unique convertion. The user has to set - // 'prepareUnique' to true first. - if (!cmrIndex->idx->prepareUnique()) { - return Status(ErrorCodes::InvalidOptions, - "Cannot make index unique with 'prepareUnique=false'. " - "Run collMod to set it first."); - } - cmr.numModifications++; if (bool unique = *cmdIndex.getUnique(); !unique) { return Status(ErrorCodes::BadValue, "'Unique: false' option is not supported"); } - // Attempting to converting a unique index should be treated as a no-op. + // Attempting to convert a unique index should be treated as a no-op. if (cmrIndex->idx->unique()) { indexObjForOplog = indexObjForOplog.removeField(CollModIndex::kUniqueFieldName); } else { + // Disallow one-step unique convertion. The user has to set + // 'prepareUnique' to true first. + if (!cmrIndex->idx->prepareUnique()) { + return Status(ErrorCodes::InvalidOptions, + "Cannot make index unique with 'prepareUnique=false'. " + "Run collMod to set it first."); + } cmrIndex->indexUnique = true; } } |