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
101
102
103
104
105
106
|
/**
* Confirms that the limit on number of aggregragation pipeline stages is respected.
* @tags: [requires_fcv_49]
*/
(function() {
"use strict";
function testLimits(testDB, lengthLimit) {
const maxLength = lengthLimit;
const tooLarge = lengthLimit + 1;
assert.commandWorked(testDB.runCommand({
aggregate: "test",
cursor: {},
pipeline: new Array(maxLength).fill({$project: {_id: 1}})
}));
assert.commandFailedWithCode(testDB.runCommand({
aggregate: "test",
cursor: {},
pipeline: new Array(tooLarge).fill({$project: {_id: 1}})
}),
ErrorCodes.FailedToParse);
testDB.setLogLevel(1);
assert.commandWorked(testDB.runCommand({
aggregate: "test",
cursor: {},
pipeline: [{
$lookup:
{from: "test", as: "as", pipeline: new Array(maxLength).fill({$project: {_id: 1}})}
}]
}));
assert.commandFailedWithCode(testDB.runCommand({
aggregate: "test",
cursor: {},
pipeline: [{
$lookup:
{from: "test", as: "as", pipeline: new Array(tooLarge).fill({$project: {_id: 1}})}
}]
}),
ErrorCodes.FailedToParse);
assert.commandWorked(testDB.runCommand({
aggregate: "test",
cursor: {},
pipeline: [
{$unionWith: {coll: "test", pipeline: new Array(maxLength).fill({$project: {_id: 1}})}}
]
}));
assert.commandFailedWithCode(testDB.runCommand({
aggregate: "test",
cursor: {},
pipeline:
[{$unionWith: {coll: "test", pipeline: new Array(tooLarge).fill({$project: {_id: 1}})}}]
}),
ErrorCodes.FailedToParse);
assert.commandWorked(testDB.runCommand({
aggregate: "test",
cursor: {},
pipeline: [{$facet: {foo: new Array(maxLength).fill({$project: {_id: 1}})}}]
}));
assert.commandFailedWithCode(testDB.runCommand({
aggregate: "test",
cursor: {},
pipeline: [{$facet: {foo: new Array(tooLarge).fill({$project: {_id: 1}}), bar: []}}]
}),
ErrorCodes.FailedToParse);
assert.commandWorked(testDB.runCommand(
{update: "test", updates: [{q: {}, u: new Array(maxLength).fill({$project: {_id: 1}})}]}));
assert.commandFailedWithCode(testDB.runCommand({
update: "test",
updates: [{q: {}, u: new Array(tooLarge).fill({$project: {_id: 1}})}]
}),
ErrorCodes.FailedToParse);
}
function runTest(lengthLimit, mongosConfig = {}, mongodConfig = {}) {
const st = new ShardingTest(
{shards: 2, rs: {nodes: 1}, other: {mongosOptions: mongosConfig, rsOptions: mongodConfig}});
assert.commandWorked(st.s0.adminCommand({enablesharding: "test"}));
assert.commandWorked(st.s0.adminCommand({shardCollection: "test.foo", key: {_id: "hashed"}}));
let mongosDB = st.s0.getDB("test");
assert.commandWorked(mongosDB.test.insert([{}, {}, {}, {}]));
// Run test against mongos.
testLimits(mongosDB, lengthLimit);
// Run test against shard.
let shard0DB = st.rs0.getPrimary().getDB("test");
testLimits(shard0DB, lengthLimit);
st.stop();
}
// Test default pipeline length limit.
runTest(1000);
// Test with modified pipeline length limit.
runTest(50,
{setParameter: {internalPipelineLengthLimit: 50}},
{setParameter: {internalPipelineLengthLimit: 50}});
})();
|