diff options
author | Charlie Swanson <charlie.swanson@mongodb.com> | 2021-06-25 07:59:45 -0400 |
---|---|---|
committer | Charlie Swanson <charlie.swanson@mongodb.com> | 2021-06-29 08:33:14 -0400 |
commit | ea3c687d439065d00c7897bbe1d50a378edacb11 (patch) | |
tree | ce17b90ae2bd5a221750d1b00d2476c5e3514c88 /jstests/core/api_version_new_50_language_features.js | |
parent | 751eb739c00c463b54823e7ab6da74c40172365f (diff) | |
download | mongo-ea3c687d439065d00c7897bbe1d50a378edacb11.tar.gz |
SERVER-58076 Exclude new 5.0 language features from stable API
(cherry picked from commit 7558a7a36cbfcc0af39b0f0bf07861f162c590d2)
Diffstat (limited to 'jstests/core/api_version_new_50_language_features.js')
-rw-r--r-- | jstests/core/api_version_new_50_language_features.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/jstests/core/api_version_new_50_language_features.js b/jstests/core/api_version_new_50_language_features.js new file mode 100644 index 00000000000..c11abd84885 --- /dev/null +++ b/jstests/core/api_version_new_50_language_features.js @@ -0,0 +1,78 @@ +/** + * Tests that language features introduced in version 4.9 or 5.0 are not included in API Version 1 + * yet. This test should be updated or removed in a future release when we have more confidence that + * the behavior and syntax is stable. + * + * @tags: [ + * requires_fcv_50, + * uses_api_parameters, + * ] + */ + +(function() { +"use strict"; + +const collName = "api_version_new_50_language_features"; +const coll = db[collName]; +coll.drop(); +assert.commandWorked(coll.insert({a: 1, date: new ISODate()})); + +const unstablePipelines = [ + [{ + $setWindowFields: { + sortBy: {_id: 1}, + output: {runningCount: {$sum: 1, window: {documents: ["unbounded", "current"]}}} + } + }], + [{$set: {x: {$dateTrunc: {date: "$date", unit: "second", binSize: 5}}}}], + [{$set: {x: {$dateAdd: {startDate: "$date", unit: "day", amount: 1}}}}], + [{$set: {x: {$dateSubtract: {startDate: "$date", unit: "day", amount: 1}}}}], + [{$set: {x: {$getField: {input: "$$ROOT", field: "x"}}}}], + [{$set: {x: {$setField: {input: "$$ROOT", field: "x", value: "foo"}}}}], +]; + +function assertAggregateFailsWithAPIStrict(pipeline) { + assert.commandFailedWithCode(db.runCommand({ + aggregate: collName, + pipeline: pipeline, + cursor: {}, + apiStrict: true, + apiVersion: "1" + }), + ErrorCodes.APIStrictError, + pipeline); +} + +for (let pipeline of unstablePipelines) { + // Assert error thrown when running a pipeline with stages not in API Version 1. + assertAggregateFailsWithAPIStrict(pipeline); + + // Assert error thrown when creating a view on a pipeline with stages not in API Version 1. + assert.commandFailedWithCode(db.runCommand({ + create: 'new_50_feature_view', + viewOn: collName, + pipeline: pipeline, + apiStrict: true, + apiVersion: "1" + }), + ErrorCodes.APIStrictError, + pipeline); + + // Assert error is not thrown when running without apiStrict=true. + assert.commandWorked(db.runCommand({ + aggregate: coll.getName(), + pipeline: pipeline, + apiVersion: "1", + cursor: {}, + })); +} + +// Creating a collection with the unstable validator is not allowed with apiStrict:true. +assert.commandFailedWithCode(db.runCommand({ + create: 'new_50_features_validator', + validator: {$expr: {$eq: [{$getField: {input: "$$ROOT", field: "dotted.path"}}, 2]}}, + apiVersion: "1", + apiStrict: true +}), + ErrorCodes.APIStrictError); +})(); |