summaryrefslogtreecommitdiff
path: root/jstests/core/administrative/apply_ops/apply_ops_invalid_index_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/administrative/apply_ops/apply_ops_invalid_index_spec.js')
-rw-r--r--jstests/core/administrative/apply_ops/apply_ops_invalid_index_spec.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/jstests/core/administrative/apply_ops/apply_ops_invalid_index_spec.js b/jstests/core/administrative/apply_ops/apply_ops_invalid_index_spec.js
new file mode 100644
index 00000000000..f24f0dfe47f
--- /dev/null
+++ b/jstests/core/administrative/apply_ops/apply_ops_invalid_index_spec.js
@@ -0,0 +1,39 @@
+/**
+ * Tests how applyOps handles index specs with unknown fields.
+ *
+ * We subject index specs with version 2 or later to stricter validation than version 1 index specs.
+ * When given an index spec with an unrecognized field, applyOps will reject v:2 indexes with an
+ * InvalidIndexSpecificationOption error while v:1 indexes are accepted as-is.
+ *
+ * @tags: [
+ * requires_non_retryable_commands,
+ * requires_fastcount,
+ * # applyOps is not supported on mongos
+ * assumes_against_mongod_not_mongos,
+ * # applyOps uses the oplog which requires replication support.
+ * requires_replication,
+ * # Tenant migrations don't support applyOps.
+ * tenant_migration_incompatible,
+ * ]
+ */
+
+(function() {
+'use strict';
+
+const t = db.apply_ops_invalid_index_spec;
+t.drop();
+
+const collNs = t.getFullName();
+const cmdNs = db.getName() + '.$cmd';
+const systemIndexesNs = db.getCollection('system.indexes').getFullName();
+
+assert.commandWorked(db.createCollection(t.getName()));
+assert.commandWorked(t.save({_id: 100, a: 100}));
+
+// Tests that db.collection.createIndex() fails when given an index spec containing an unknown
+// field.
+assert.commandFailedWithCode(t.createIndex({a: 1}, {v: 2, name: 'a_1_base_v2', unknown: 1}),
+ ErrorCodes.InvalidIndexSpecificationOption);
+assert.commandFailedWithCode(t.createIndex({a: 1}, {v: 1, name: 'a_1_base_v1', unknown: 1}),
+ ErrorCodes.InvalidIndexSpecificationOption);
+})();