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
|
// The test runs commands that are not allowed with security token: mapReduce.
// @tags: [
// not_allowed_with_security_token,
// does_not_support_stepdowns,
// requires_fastcount,
// requires_getmore,
// requires_non_retryable_writes,
// # This test has statements that do not support non-local read concern.
// does_not_support_causal_consistency,
// # Uses mapReduce command.
// requires_scripting,
// ]
load("jstests/aggregation/extras/utils.js"); // For resultsEq
(function() {
"use strict";
const coll = db.map_reduce_subplanning;
coll.drop();
db.getCollection("mrOutput").drop();
coll.createIndex({a: 1, c: 1});
coll.createIndex({b: 1, c: 1});
coll.createIndex({a: 1});
coll.createIndex({b: 1});
assert.commandWorked(coll.insert({a: 2}));
assert.commandWorked(coll.insert({b: 3}));
assert.commandWorked(coll.insert({b: 3}));
assert.commandWorked(coll.insert({a: 2, b: 3}));
assert.commandWorked(coll.mapReduce(
function() {
if (!this.hasOwnProperty('a')) {
emit('a', 0);
} else {
emit('a', this.a);
}
},
function(key, vals) {
return vals.reduce((a, b) => a + b, 0);
},
{out: {merge: "mrOutput"}, query: {$or: [{a: 2}, {b: 3}]}}));
assert(resultsEq([{"_id": "a", "value": 4}], db.getCollection("mrOutput").find().toArray()),
db.getCollection("mrOutput").find().toArray());
})();
|