1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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);
})();
|