summaryrefslogtreecommitdiff
path: root/jstests/core/collmod.js
diff options
context:
space:
mode:
authorDavid Hatch <david.hatch@mongodb.com>2016-07-22 13:32:56 -0400
committerDavid Hatch <david.hatch@mongodb.com>2016-08-02 10:56:35 -0400
commit4caf167d193b3b6b4a4cf584f1d903de631a13ef (patch)
tree82bc4d2cddaffe835faed524aa076afdcb069a74 /jstests/core/collmod.js
parent3ec5815c8cfa64316358046de0b33a44a60c292f (diff)
downloadmongo-4caf167d193b3b6b4a4cf584f1d903de631a13ef.tar.gz
SERVER-24239 Add support to collMod command for index names.
Diffstat (limited to 'jstests/core/collmod.js')
-rw-r--r--jstests/core/collmod.js42
1 files changed, 40 insertions, 2 deletions
diff --git a/jstests/core/collmod.js b/jstests/core/collmod.js
index 7e899294788..16f9694560c 100644
--- a/jstests/core/collmod.js
+++ b/jstests/core/collmod.js
@@ -21,6 +21,14 @@ function findTTL(key, expireAfterSeconds) {
return all.length == 1;
}
+function findTTLByName(name, expireAfterSeconds) {
+ var all = t.getIndexes();
+ all = all.filter(function(z) {
+ return z.expireAfterSeconds == expireAfterSeconds && z.name == name;
+ });
+ return all.length == 1;
+}
+
function findCollectionInfo() {
var all = db.getCollectionInfos();
all = all.filter(function(z) {
@@ -34,7 +42,7 @@ function findCollectionInfo() {
assert.commandFailed(t.runCommand('collmod', {NotARealOption: 1}));
// add a TTL index
-t.ensureIndex({a: 1}, {"expireAfterSeconds": 50});
+t.ensureIndex({a: 1}, {"name": "index1", "expireAfterSeconds": 50});
assert(findTTL({a: 1}, 50), "TTL index not added");
// try to modify it with a bad key pattern
@@ -43,6 +51,10 @@ var res =
debug(res);
assert.eq(0, res.ok, "mod shouldn't work with bad keypattern");
+// Ensure collMod fails with a non-string indexName.
+var res = db.runCommand({"collMod": coll, "index": {"indexName": 2, "expireAfterSeconds": 120}});
+assert.commandFailed(res);
+
// try to modify it without expireAfterSeconds field
var res = db.runCommand({"collMod": coll, "index": {"keyPattern": {a: 1}}});
debug(res);
@@ -60,6 +72,19 @@ var res =
debug(res);
assert(findTTL({a: 1}, 100), "TTL index not modified");
+// Modify ttl index by name.
+var res = db.runCommand({"collMod": coll, "index": {"name": "index1", "expireAfterSeconds": 500}});
+assert(findTTL({a: 1}, 500), "TTL index not modified");
+
+// Must specify key pattern or name.
+assert.commandFailed(db.runCommand({"collMod": coll, "index": {}}));
+
+// Not allowed to specify key pattern and name.
+assert.commandFailed(db.runCommand({
+ "collMod": coll,
+ "index": {"keyPattern": {a: 1}, "name": "index1", "expireAfterSeconds": 1000}
+}));
+
// try to modify a faulty TTL index with a non-numeric expireAfterSeconds field
t.dropIndex({a: 1});
t.ensureIndex({a: 1}, {"expireAfterSeconds": "50"});
@@ -98,7 +123,7 @@ if (!isMongos) {
var info = findCollectionInfo();
assert.eq(info.options.flags, 0, tojson(info));
-// Tests that collmod does not accept an ambiguous index key pattern.
+// Tests for collmod over multiple indexes with the same key pattern.
t.drop();
assert.commandWorked(db.createCollection(coll));
t = db.getCollection(coll);
@@ -112,3 +137,16 @@ assert.commandWorked(
assert.commandFailed(
db.runCommand({collMod: coll, index: {keyPattern: {a: 1}, expireAfterSeconds: 240}}));
assert(!findTTL({a: 1}, 240), "TTL index modified.");
+
+// Ensure that a single TTL index is modified by name.
+assert.commandWorked(db.runCommand({collMod: coll, index: {name: "TTL", expireAfterSeconds: 100}}));
+assert(findTTLByName("TTL", 100), "TTL index not modified.");
+assert(findTTLByName("TTLfr", 120), "TTL index modified.");
+
+// Fails with an unknown index name.
+assert.commandFailed(
+ db.runCommand({collMod: coll, index: {name: "notaname", expireAfterSeconds: 100}}));
+
+// Fails with an unknown key pattern.
+assert.commandFailed(db.runCommand(
+ {collmod: coll, index: {keyPattern: {doesnotexist: 1}, expireAfterSeconds: 100}}));