diff options
author | Damian Wasilewicz <damian.wasilewicz@mongodb.com> | 2022-06-29 15:20:51 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-06-29 17:35:00 +0000 |
commit | 37d3534f0d6212cf3e89785152a1fdaa180cceeb (patch) | |
tree | a5b403445affda2daa32c32ade08103ede082605 /jstests | |
parent | 11aa6d3c5166f0e8dcaefca691d303b9c0af3dc9 (diff) | |
download | mongo-37d3534f0d6212cf3e89785152a1fdaa180cceeb.tar.gz |
SERVER-66976 Enabled validation for time-series collections
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/noPassthroughWithMongod/validate_timeseries.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/validate_timeseries.js b/jstests/noPassthroughWithMongod/validate_timeseries.js new file mode 100644 index 00000000000..3d08ec0a8d3 --- /dev/null +++ b/jstests/noPassthroughWithMongod/validate_timeseries.js @@ -0,0 +1,68 @@ +/* + * Tests that calling the validate command on a time-series collection is allowed, while ensuring + * that calling validate on non-time-series views is still prohibited, even if a collection with the + * bucket namespace of that view exists. + * + * @tags: [ + * featureFlagExtendValidateCommand + * ] + */ + +(function() { +"use strict"; + +db.validate_timeseries.drop(); +db.system.buckets.validate_timeseries.drop(); +db.viewSource.drop(); +db.view.drop(); +db.system.buckets.view.drop(); + +assert.commandWorked(db.createCollection( + "validate_timeseries", + {timeseries: {timeField: "timestamp", metaField: "metadata", granularity: "hours"}})); + +const coll = db.validate_timeseries; +const bucketColl = db.system.buckets.validate_timeseries; +const weather_data = [ + { + "metadata": {"sensorId": 5578, "type": "temperature"}, + "timestamp": ISODate("2021-05-18T00:00:00.000Z"), + "temp": 12 + }, + { + "metadata": {"sensorId": 5578, "type": "temperature"}, + "timestamp": ISODate("2021-05-18T04:00:00.000Z"), + "temp": 11 + }, +]; + +assert.commandWorked(coll.insertMany(weather_data)); + +// Tests that the validate command can be run on a time-series collection. + +let res = assert.commandWorked(coll.validate()); +assert(res.valid, tojson(res)); + +res = assert.commandWorked(bucketColl.validate()); +assert(res.valid, tojson(res)); + +// Tests that the validate command doesn't run on a view without a bucket collection. +assert.commandWorked(db.createCollection("viewSource")); + +assert.commandWorked(db.createView("view", "viewSource", [{$project: {"Name": "$temp"}}])); + +const viewSource = db.viewSource; +const view = db.view; + +res = assert.commandWorked(viewSource.validate()); +assert(res.valid, tojson(res)); + +assert.commandFailedWithCode(view.validate(), ErrorCodes.CommandNotSupportedOnView); + +// Tests that the validate command doesn't run on a view with a non-time-series bucket collection. +assert.commandWorked(db.createCollection("system.buckets.view")); + +assert.commandFailedWithCode(view.validate(), ErrorCodes.CommandNotSupportedOnView); + +// +})(); |