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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/**
* Tests commands(e.g. aggregate, create) that use pipeline stages not supported in API Version 1.
*
* Tests which create views aren't expected to work when collections are implicitly sharded.
* @tags: [
* assumes_read_concern_unchanged,
* assumes_read_preference_unchanged,
* assumes_unsharded_collection,
* uses_api_parameters,
* ]
*/
(function() {
"use strict";
const collName = "api_version_pipeline_stages";
const coll = db[collName];
coll.drop();
coll.insert({a: 1});
const unstablePipelines = [
[{$collStats: {count: {}, latencyStats: {}}}],
[{$currentOp: {}}],
[{$indexStats: {}}],
[{$listLocalSessions: {}}],
[{$listSessions: {}}],
[{$planCacheStats: {}}],
[{$unionWith: {coll: "coll2", pipeline: [{$collStats: {latencyStats: {}}}]}}],
[{$lookup: {from: "coll2", pipeline: [{$indexStats: {}}]}}],
[{$lookup: {from: "coll2", _internalCollation: {locale: "simple"}}}],
[{$facet: {field1: [], field2: [{$indexStats: {}}]}}],
];
function assertAggregateFailsWithAPIStrict(pipeline) {
assert.commandFailedWithCode(db.runCommand({
aggregate: collName,
pipeline: pipeline,
cursor: {},
apiStrict: true,
apiVersion: "1"
}),
ErrorCodes.APIStrictError);
}
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: 'api_version_pipeline_stages_should_fail',
viewOn: collName,
pipeline: pipeline,
apiStrict: true,
apiVersion: "1"
}),
ErrorCodes.APIStrictError);
}
// Test that $collStats is allowed in APIVersion 1, even with 'apiStrict: true', so long as the only
// parameter given is 'count'.
assertAggregateFailsWithAPIStrict([{$collStats: {latencyStats: {}}}]);
assertAggregateFailsWithAPIStrict([{$collStats: {latencyStats: {histograms: true}}}]);
assertAggregateFailsWithAPIStrict([{$collStats: {storageStats: {}}}]);
assertAggregateFailsWithAPIStrict([{$collStats: {queryExecStats: {}}}]);
assertAggregateFailsWithAPIStrict([{$collStats: {latencyStats: {}, queryExecStats: {}}}]);
assertAggregateFailsWithAPIStrict(
[{$collStats: {latencyStats: {}, storageStats: {scale: 1024}, queryExecStats: {}}}]);
assert.commandWorked(db.runCommand({
aggregate: collName,
pipeline: [{$collStats: {}}],
cursor: {},
apiVersion: "1",
apiStrict: true
}));
assert.commandWorked(db.runCommand({
aggregate: collName,
pipeline: [{$collStats: {count: {}}}],
cursor: {},
apiVersion: "1",
apiStrict: true
}));
// Test that by running the aggregate command with $collStats + $group like our drivers do to
// compute the count, we get back a single result in the first batch - no getMore is required.
// This test is meant to mimic a drivers test and serve as a warning if we may be making a breaking
// change for the drivers.
const cmdResult = assert.commandWorked(db.runCommand({
aggregate: collName,
pipeline: [{$collStats: {count: {}}}, {$group: {_id: 1, count: {$sum: "$count"}}}],
cursor: {},
apiVersion: "1",
apiStrict: true
}));
assert.eq(cmdResult.cursor.id, 0, cmdResult);
assert.eq(cmdResult.cursor.firstBatch.length, 1, cmdResult);
assert.eq(cmdResult.cursor.firstBatch[0].count, 1, cmdResult);
})();
|