summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-05-09 11:43:49 -0400
committerGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-05-10 09:59:00 -0400
commitf93289333344bf097e2010899cc7ec19e52fe3cd (patch)
tree4fca7556ac6e552c0e35f3b761be282818c0666e
parentbf6c2696da7eb207c28e83f5bb7401c97b0f69ac (diff)
downloadmongo-f93289333344bf097e2010899cc7ec19e52fe3cd.tar.gz
SERVER-40660 Ensure multiple indexes via createIndexes() cannot bypass index limits
-rw-r--r--jstests/noPassthroughWithMongod/index_limits_not_bypassed.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/index_limits_not_bypassed.js b/jstests/noPassthroughWithMongod/index_limits_not_bypassed.js
new file mode 100644
index 00000000000..bc55bda6550
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/index_limits_not_bypassed.js
@@ -0,0 +1,38 @@
+/**
+ * Ensures that we cannot bypass the 64 index limit or the 1 text index limit per collection using
+ * the 'createIndexes()' command to create multiple indexes in one request.
+ */
+(function() {
+ "use strict";
+
+ const collName = "index_limits_not_bypassed";
+ const coll = db.getCollection(collName);
+ coll.drop();
+
+ // A single collection can have no more than 64 indexes. We'll create 62 indexes here to
+ // have a total of 63 indexes (the _id index and the 62 about to be created).
+ for (let index = 0; index < 62; index++) {
+ let spec = {};
+ spec[index] = 1;
+ assert.commandWorked(coll.createIndex(spec));
+ }
+
+ let indexes = db.runCommand({listIndexes: collName});
+ assert.eq(63, indexes.cursor.firstBatch.length);
+
+ // Creating multiple indexes via 'createIndexes()' shouldn't bypass index limits.
+ assert.commandFailedWithCode(coll.createIndexes([{x: 1}, {y: 1}]),
+ ErrorCodes.CannotCreateIndex);
+
+ assert.commandFailedWithCode(coll.dropIndex("x"), ErrorCodes.IndexNotFound);
+ assert.commandFailedWithCode(coll.dropIndex("y"), ErrorCodes.IndexNotFound);
+
+ // Try to create two text indexes at the same time using 'createIndexes()'. The limit for text
+ // indexes is one per collection.
+ assert.commandFailedWithCode(
+ coll.createIndexes([{x: "text", weights: {x: 5}}, {y: "text", weights: {y: 10}}]),
+ ErrorCodes.CannotCreateIndex);
+
+ assert.commandFailedWithCode(coll.dropIndex("x"), ErrorCodes.IndexNotFound);
+ assert.commandFailedWithCode(coll.dropIndex("y"), ErrorCodes.IndexNotFound);
+}());