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
|
// @tags: [
// does_not_support_stepdowns,
// uses_testing_only_commands,
// ]
// Test limit and skip
t = db.stages_limit_skip;
t.drop();
var collname = "stages_limit_skip";
var N = 50;
for (var i = 0; i < N; ++i) {
t.insert({foo: i, bar: N - i, baz: i});
}
t.ensureIndex({foo: 1});
// foo <= 20, decreasing
// Limit of 5 results.
ixscan1 = {
ixscan: {
args: {
keyPattern: {foo: 1},
startKey: {"": 20},
endKey: {},
startKeyInclusive: true,
endKeyInclusive: true,
direction: -1
}
}
};
limit1 = {
limit: {args: {node: ixscan1, num: 5}}
};
res = db.runCommand({stageDebug: {collection: collname, plan: limit1}});
assert.eq(res.ok, 1);
assert.eq(res.results.length, 5);
assert.eq(res.results[0].foo, 20);
assert.eq(res.results[4].foo, 16);
// foo <= 20, decreasing
// Skip 5 results.
skip1 = {
skip: {args: {node: ixscan1, num: 5}}
};
res = db.runCommand({stageDebug: {collection: collname, plan: skip1}});
assert.eq(res.ok, 1);
assert.eq(res.results.length, 16);
assert.eq(res.results[0].foo, 15);
assert.eq(res.results[res.results.length - 1].foo, 0);
|