diff --git a/jstests/core/create_indexes_with_unknown_field_names.js b/jstests/core/create_indexes_with_unknown_field_names.js index 2537a486157..c5cfefff3a5 100644 --- a/jstests/core/create_indexes_with_unknown_field_names.js +++ b/jstests/core/create_indexes_with_unknown_field_names.js @@ -1,6 +1,6 @@ /** * Tests that we can have unknown field names in the index spec passed to the createIndexes command - * if 'ignoreUnknownIndexSpecFields: true' is set on the createIndexes command. + * if 'ignoreUnknownIndexOptions: true' is set on the createIndexes command. */ (function() { "use strict"; @@ -15,21 +15,21 @@ assert.commandFailedWithCode(db.runCommand({ createIndexes: "unknown_field_names_create_indexes", indexes: [{key: {x: 1}, name: "myindex", someField: "someValue"}], - ignoreUnknownIndexSpecFields: false + ignoreUnknownIndexOptions: false }), ErrorCodes.InvalidIndexSpecificationOption); assert.commandFailedWithCode(db.runCommand({ createIndexes: "unknown_field_names_create_indexes", indexes: [{key: {x: 1}, name: "myindex", someField: "someValue"}], - ignoreUnknownIndexSpecFields: "badValue" + ignoreUnknownIndexOptions: "badValue" }), ErrorCodes.TypeMismatch); assert.commandWorked(db.runCommand({ createIndexes: "unknown_field_names_create_indexes", indexes: [{key: {x: 1}, name: "myindex", someField: "someValue"}], - ignoreUnknownIndexSpecFields: true + ignoreUnknownIndexOptions: true })); // Make sure 'someField' is not in the index spec. diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 7b0dbb11cce..89c47545edc 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -70,7 +70,7 @@ namespace { constexpr auto kIndexesFieldName = "indexes"_sd; constexpr auto kCommandName = "createIndexes"_sd; constexpr auto kCommitQuorumFieldName = "commitQuorum"_sd; -constexpr auto kignoreUnknownIndexSpecFieldsName = "ignoreUnknownIndexSpecFields"_sd; +constexpr auto kIgnoreUnknownIndexOptionsName = "ignoreUnknownIndexOptions"_sd; constexpr auto kTwoPhaseCommandName = "twoPhaseCreateIndexes"_sd; constexpr auto kCreateCollectionAutomaticallyFieldName = "createdCollectionAutomatically"_sd; constexpr auto kNumIndexesBeforeFieldName = "numIndexesBefore"_sd; @@ -89,17 +89,16 @@ StatusWith> parseAndValidateIndexSpecs( const ServerGlobalParams::FeatureCompatibility& featureCompatibility) { bool hasIndexesField = false; - bool ignoreUnknownIndexSpecFields = false; - if (cmdObj.hasField(kignoreUnknownIndexSpecFieldsName)) { - auto ignoreUnknownIndexSpecFieldsElement = - cmdObj.getField(kignoreUnknownIndexSpecFieldsName); - if (ignoreUnknownIndexSpecFieldsElement.type() != BSONType::Bool) { + bool ignoreUnknownIndexOptions = false; + if (cmdObj.hasField(kIgnoreUnknownIndexOptionsName)) { + auto ignoreUnknownIndexOptionsElement = cmdObj.getField(kIgnoreUnknownIndexOptionsName); + if (ignoreUnknownIndexOptionsElement.type() != BSONType::Bool) { return {ErrorCodes::TypeMismatch, - str::stream() << "The field '" << kignoreUnknownIndexSpecFieldsName + str::stream() << "The field '" << kIgnoreUnknownIndexOptionsName << "' must be a boolean, but got " - << typeName(ignoreUnknownIndexSpecFieldsElement.type())}; + << typeName(ignoreUnknownIndexOptionsElement.type())}; } - ignoreUnknownIndexSpecFields = ignoreUnknownIndexSpecFieldsElement.boolean(); + ignoreUnknownIndexOptions = ignoreUnknownIndexOptionsElement.boolean(); } std::vector indexSpecs; @@ -123,7 +122,7 @@ StatusWith> parseAndValidateIndexSpecs( } BSONObj parsedIndexSpec = indexesElem.Obj(); - if (ignoreUnknownIndexSpecFields) { + if (ignoreUnknownIndexOptions) { parsedIndexSpec = index_key_validate::removeUnknownFields(parsedIndexSpec); } @@ -158,7 +157,7 @@ StatusWith> parseAndValidateIndexSpecs( hasIndexesField = true; } else if (kCommandName == cmdElemFieldName || kCommitQuorumFieldName == cmdElemFieldName || kTwoPhaseCommandName == cmdElemFieldName || - kignoreUnknownIndexSpecFieldsName == cmdElemFieldName || + kIgnoreUnknownIndexOptionsName == cmdElemFieldName || isGenericArgument(cmdElemFieldName)) { continue; } else {