diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-02-21 16:57:35 -0500 |
---|---|---|
committer | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-02-25 18:43:52 -0500 |
commit | 8464972fec625390c4856f2fc364ae4a561b511d (patch) | |
tree | c5a1111f289b95f5a61a35e31b28008e4403cfa9 /jstests | |
parent | d2850ae4977e376a30ebd542d92fd56c643fbede (diff) | |
download | mongo-8464972fec625390c4856f2fc364ae4a561b511d.tar.gz |
SERVER-39669 Support creating index builds with unknown options
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/create_indexes_with_unknown_field_names.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/jstests/core/create_indexes_with_unknown_field_names.js b/jstests/core/create_indexes_with_unknown_field_names.js new file mode 100644 index 00000000000..2537a486157 --- /dev/null +++ b/jstests/core/create_indexes_with_unknown_field_names.js @@ -0,0 +1,42 @@ +/** + * 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. + */ +(function() { + "use strict"; + + db.unknown_field_names_create_indexes.drop(); + assert.commandFailedWithCode(db.runCommand({ + createIndexes: "unknown_field_names_create_indexes", + indexes: [{key: {x: 1}, name: "myindex", someField: "someValue"}] + }), + ErrorCodes.InvalidIndexSpecificationOption); + + assert.commandFailedWithCode(db.runCommand({ + createIndexes: "unknown_field_names_create_indexes", + indexes: [{key: {x: 1}, name: "myindex", someField: "someValue"}], + ignoreUnknownIndexSpecFields: false + }), + ErrorCodes.InvalidIndexSpecificationOption); + + assert.commandFailedWithCode(db.runCommand({ + createIndexes: "unknown_field_names_create_indexes", + indexes: [{key: {x: 1}, name: "myindex", someField: "someValue"}], + ignoreUnknownIndexSpecFields: "badValue" + }), + ErrorCodes.TypeMismatch); + + assert.commandWorked(db.runCommand({ + createIndexes: "unknown_field_names_create_indexes", + indexes: [{key: {x: 1}, name: "myindex", someField: "someValue"}], + ignoreUnknownIndexSpecFields: true + })); + + // Make sure 'someField' is not in the index spec. + let indexes = db.unknown_field_names_create_indexes.getIndexes(); + for (let index in indexes) { + if (0 === bsonWoCompare(indexes[index].key, {x: 1})) { + assert.eq(indexes[index].someField, undefined); + } + } +})(); |