diff options
author | Yuhong Zhang <danielzhangyh@gmail.com> | 2021-09-28 12:52:59 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-09-28 13:26:16 +0000 |
commit | 1f4dbc3e2981b5f32e468f0c6bbf392bd6489a2e (patch) | |
tree | 403e96cfa366617df13da6739ca2024a858ca139 /jstests/core | |
parent | efeb503a68bbbc5283f3e3d813ae189ab70984dc (diff) | |
download | mongo-1f4dbc3e2981b5f32e468f0c6bbf392bd6489a2e.tar.gz |
SERVER-58130 Disable incompatible collMod options for time-series collections
Diffstat (limited to 'jstests/core')
-rw-r--r-- | jstests/core/collmod_convert_to_ttl.js | 50 | ||||
-rw-r--r-- | jstests/core/timeseries/timeseries_collmod.js | 59 |
2 files changed, 85 insertions, 24 deletions
diff --git a/jstests/core/collmod_convert_to_ttl.js b/jstests/core/collmod_convert_to_ttl.js index b5803db68d2..e1e66ea7a0b 100644 --- a/jstests/core/collmod_convert_to_ttl.js +++ b/jstests/core/collmod_convert_to_ttl.js @@ -5,60 +5,62 @@ * # Cannot implicitly shard accessed collections because of collection existing when none * # expected. * assumes_no_implicit_collection_creation_after_drop, - * * requires_non_retryable_commands, * requires_ttl_index, - * multiversion_incompatible, + * requires_fcv_51, * ] */ (function() { 'use strict'; -let collName = "collmod_convert_to_ttl"; -let coll = db.getCollection(collName); +const collName = "collmod_convert_to_ttl"; +const coll = db.getCollection(collName); coll.drop(); db.createCollection(collName); function findTTL(key, expireAfterSeconds) { - let all = coll.getIndexes(); - all = all.filter(function(z) { + const all = coll.getIndexes().filter(function(z) { return z.expireAfterSeconds == expireAfterSeconds && friendlyEqual(z.key, key); }); return all.length == 1; } // Creates a regular index and use collMod to convert it to a TTL index. -coll.dropIndex({a: 1}); coll.createIndex({a: 1}); // Tries to modify with a string 'expireAfterSeconds' value. -let res = db.runCommand( - {"collMod": collName, "index": {"keyPattern": {a: 1}, "expireAfterSeconds": "100"}}); -assert.commandFailedWithCode(res, ErrorCodes.TypeMismatch); +assert.commandFailedWithCode( + db.runCommand( + {"collMod": collName, "index": {"keyPattern": {a: 1}, "expireAfterSeconds": "100"}}), + ErrorCodes.TypeMismatch); // Tries to modify with a negative 'expireAfterSeconds' value. -res = - db.runCommand({"collMod": collName, "index": {"keyPattern": {a: 1}, "expireAfterSeconds": -1}}); -assert.commandFailedWithCode(res, ErrorCodes.InvalidOptions); +assert.commandFailedWithCode( + db.runCommand({"collMod": collName, "index": {"keyPattern": {a: 1}, "expireAfterSeconds": -1}}), + ErrorCodes.InvalidOptions); // Tries to modify with an 'expireAfterSeconds' value too large. -res = db.runCommand( - {"collMod": collName, "index": {"keyPattern": {a: 1}, "expireAfterSeconds": 10000000000000}}); -assert.commandFailedWithCode(res, ErrorCodes.InvalidOptions); +assert.commandFailedWithCode(db.runCommand({ + "collMod": collName, + "index": {"keyPattern": {a: 1}, "expireAfterSeconds": 10000000000000} +}), + ErrorCodes.InvalidOptions); // Successfully converts to a TTL index. -res = db.runCommand( - {"collMod": collName, "index": {"keyPattern": {a: 1}, "expireAfterSeconds": 100}}); +assert.commandWorked(db.runCommand( + {"collMod": collName, "index": {"keyPattern": {a: 1}, "expireAfterSeconds": 100}})); assert(findTTL({a: 1}, 100), "TTL index should be 100 now"); // Tries to convert a compound index to a TTL index. coll.createIndex({a: 1, b: 1}); -res = db.runCommand( - {"collMod": collName, "index": {"keyPattern": {a: 1, b: 1}, "expireAfterSeconds": 100}}); -assert.commandFailedWithCode(res, ErrorCodes.InvalidOptions); +assert.commandFailedWithCode( + db.runCommand( + {"collMod": collName, "index": {"keyPattern": {a: 1, b: 1}, "expireAfterSeconds": 100}}), + ErrorCodes.InvalidOptions); // Tries to convert the '_id' index to a TTL index. -res = db.runCommand( - {"collMod": collName, "index": {"keyPattern": {_id: 1}, "expireAfterSeconds": 100}}); -assert.commandFailedWithCode(res, ErrorCodes.InvalidOptions); +assert.commandFailedWithCode( + db.runCommand( + {"collMod": collName, "index": {"keyPattern": {_id: 1}, "expireAfterSeconds": 100}}), + ErrorCodes.InvalidOptions); })();
\ No newline at end of file diff --git a/jstests/core/timeseries/timeseries_collmod.js b/jstests/core/timeseries/timeseries_collmod.js new file mode 100644 index 00000000000..69fd7dbeb82 --- /dev/null +++ b/jstests/core/timeseries/timeseries_collmod.js @@ -0,0 +1,59 @@ +/** + * This tests which collMod options are allowed on a time-series collection. + * + * @tags: [ + * # Cannot implicitly shard accessed collections because of collection existing when none + * # expected. + * assumes_no_implicit_collection_creation_after_drop, + * requires_non_retryable_commands, + * requires_fcv_51, + * ] + */ + +(function() { +'use strict'; +const collName = "timeseries_collmod"; +const coll = db.getCollection(collName); +coll.drop(); +assert.commandWorked( + db.createCollection(collName, {timeseries: {timeField: "time", granularity: 'seconds'}})); +assert.commandWorked(coll.createIndex({"time": 1})); + +// Tries to convert a time-series secondary index to TTL index. +assert.commandFailedWithCode( + db.runCommand( + {"collMod": collName, "index": {"keyPattern": {"time": 1}, "expireAfterSeconds": 100}}), + ErrorCodes.InvalidOptions); + +// Successfully hides a time-series secondary index. +assert.commandWorked( + db.runCommand({"collMod": collName, "index": {"keyPattern": {"time": 1}, "hidden": true}})); + +// Tries to set the validator for a time-series collection. +assert.commandFailedWithCode( + db.runCommand({"collMod": collName, "validator": {required: ["time"]}}), + ErrorCodes.InvalidOptions); + +// Tries to set the validationLevel for a time-series collection. +assert.commandFailedWithCode(db.runCommand({"collMod": collName, "validationLevel": "moderate"}), + ErrorCodes.InvalidOptions); + +// Tries to set the validationAction for a time-series collection. +assert.commandFailedWithCode(db.runCommand({"collMod": collName, "validationAction": "warn"}), + ErrorCodes.InvalidOptions); + +// Tries to modify the view for a time-series collection. +assert.commandFailedWithCode(db.runCommand({"collMod": collName, "viewOn": "foo", "pipeline": []}), + ErrorCodes.InvalidOptions); + +// Tries to set 'recordPreImages' for a time-series collection. +assert.commandFailedWithCode(db.runCommand({"collMod": collName, "recordPreImages": true}), + ErrorCodes.InvalidOptions); + +// Successfully sets 'expireAfterSeconds' for a time-series collection. +assert.commandWorked(db.runCommand({"collMod": collName, "expireAfterSeconds": 60})); + +// Successfully sets the granularity for a time-series collection. +assert.commandWorked( + db.runCommand({"collMod": collName, "timeseries": {"granularity": "minutes"}})); +})();
\ No newline at end of file |