summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod
diff options
context:
space:
mode:
authorGabriel Marks <gabriel.marks@mongodb.com>2021-11-18 19:35:30 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-11-18 22:49:22 +0000
commitba0fe9ac83cb253655a5ef79a396dcd432dcd69e (patch)
tree75226a37633e05733c31211006948123b7e10ff1 /jstests/noPassthroughWithMongod
parent5c186ebcd37f16e9acca78e4d9d3a1436b9da61d (diff)
downloadmongo-ba0fe9ac83cb253655a5ef79a396dcd432dcd69e.tar.gz
SERVER-26287 Disallow creation of TTL indexes on capped collections
Diffstat (limited to 'jstests/noPassthroughWithMongod')
-rw-r--r--jstests/noPassthroughWithMongod/ttl_index_capped_collection_fails.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/ttl_index_capped_collection_fails.js b/jstests/noPassthroughWithMongod/ttl_index_capped_collection_fails.js
new file mode 100644
index 00000000000..18ce357341f
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/ttl_index_capped_collection_fails.js
@@ -0,0 +1,22 @@
+/**
+ * Tests that attempting to create a TTL index on a capped collection will fail.
+ */
+
+(function() {
+"use strict";
+
+// Ensure that on an uncapped collection, both non-TTL and TTL indexes can be created
+const uncappedColl = db.getCollection(jsTestName() + "_uncapped");
+uncappedColl.drop();
+assert.commandWorked(db.createCollection(uncappedColl.getName(), {capped: false}));
+assert.commandWorked(uncappedColl.createIndex({foo: 1}));
+assert.commandWorked(uncappedColl.createIndex({bar: 1}, {expireAfterSeconds: 10}));
+
+// Ensure that on a capped collection, a TTL index cannot be created.
+const cappedColl = db.getCollection(jsTestName() + "_capped");
+cappedColl.drop();
+assert.commandWorked(db.createCollection(cappedColl.getName(), {capped: true, size: 102400}));
+assert.commandWorked(cappedColl.createIndex({foo: 1}));
+assert.commandFailedWithCode(cappedColl.createIndex({bar: 1}, {expireAfterSeconds: 10}),
+ ErrorCodes.CannotCreateIndex);
+})(); \ No newline at end of file