diff options
Diffstat (limited to 'jstests/core/ttl_index_options.js')
-rw-r--r-- | jstests/core/ttl_index_options.js | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/jstests/core/ttl_index_options.js b/jstests/core/ttl_index_options.js index f4d3c4b3e42..47ae2709073 100644 --- a/jstests/core/ttl_index_options.js +++ b/jstests/core/ttl_index_options.js @@ -4,42 +4,40 @@ * @tags: [requires_ttl_index] */ (function() { - 'use strict'; - - let coll = db.core_ttl_index_options; - coll.drop(); - - // Ensure that any overflows are caught when converting from seconds to milliseconds. - assert.commandFailedWithCode( - coll.createIndexes([{x: 1}], {expireAfterSeconds: 9223372036854775808}), - ErrorCodes.CannotCreateIndex); - assert.commandFailedWithCode( - coll.createIndexes([{x: 1}], {expireAfterSeconds: 9999999999999999}), - ErrorCodes.CannotCreateIndex); - - // Ensure that we cannot provide a time that is larger than the current epoch time. - let secondsSinceEpoch = Date.now() / 1000; - assert.commandFailedWithCode( - coll.createIndexes([{x: 1}], {expireAfterSeconds: secondsSinceEpoch + 1000}), - ErrorCodes.CannotCreateIndex); - - // 'expireAfterSeconds' cannot be less than 0. - assert.commandFailedWithCode(coll.createIndexes([{x: 1}], {expireAfterSeconds: -1}), - ErrorCodes.CannotCreateIndex); - assert.commandWorked(coll.createIndexes([{z: 1}], {expireAfterSeconds: 0})); - - // Compound indexes are not support with TTL indexes. - assert.commandFailedWithCode(coll.createIndexes([{x: 1, y: 1}], {expireAfterSeconds: 100}), - ErrorCodes.CannotCreateIndex); - - // 'expireAfterSeconds' should be a number. - assert.commandFailedWithCode( - coll.createIndexes([{x: 1}], {expireAfterSeconds: "invalidOption"}), - ErrorCodes.CannotCreateIndex); - - // Using 'expireAfterSeconds' as an index key is valid, but doesn't create a TTL index. - assert.commandWorked(coll.createIndexes([{x: 1, expireAfterSeconds: 3600}])); - - // Create a valid TTL index. - assert.commandWorked(coll.createIndexes([{x: 1}, {y: 1}], {expireAfterSeconds: 3600})); +'use strict'; + +let coll = db.core_ttl_index_options; +coll.drop(); + +// Ensure that any overflows are caught when converting from seconds to milliseconds. +assert.commandFailedWithCode( + coll.createIndexes([{x: 1}], {expireAfterSeconds: 9223372036854775808}), + ErrorCodes.CannotCreateIndex); +assert.commandFailedWithCode(coll.createIndexes([{x: 1}], {expireAfterSeconds: 9999999999999999}), + ErrorCodes.CannotCreateIndex); + +// Ensure that we cannot provide a time that is larger than the current epoch time. +let secondsSinceEpoch = Date.now() / 1000; +assert.commandFailedWithCode( + coll.createIndexes([{x: 1}], {expireAfterSeconds: secondsSinceEpoch + 1000}), + ErrorCodes.CannotCreateIndex); + +// 'expireAfterSeconds' cannot be less than 0. +assert.commandFailedWithCode(coll.createIndexes([{x: 1}], {expireAfterSeconds: -1}), + ErrorCodes.CannotCreateIndex); +assert.commandWorked(coll.createIndexes([{z: 1}], {expireAfterSeconds: 0})); + +// Compound indexes are not support with TTL indexes. +assert.commandFailedWithCode(coll.createIndexes([{x: 1, y: 1}], {expireAfterSeconds: 100}), + ErrorCodes.CannotCreateIndex); + +// 'expireAfterSeconds' should be a number. +assert.commandFailedWithCode(coll.createIndexes([{x: 1}], {expireAfterSeconds: "invalidOption"}), + ErrorCodes.CannotCreateIndex); + +// Using 'expireAfterSeconds' as an index key is valid, but doesn't create a TTL index. +assert.commandWorked(coll.createIndexes([{x: 1, expireAfterSeconds: 3600}])); + +// Create a valid TTL index. +assert.commandWorked(coll.createIndexes([{x: 1}, {y: 1}], {expireAfterSeconds: 3600})); }()); |