summaryrefslogtreecommitdiff
path: root/jstests/core/mr_null_arguments.js
blob: 5cca821065608d2a684da338c8ac5341ee4d2a3e (plain)
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
// Test that MapReduce only runs when certain arguments are explicit null. This is required because
// the Java Driver adds null as an argument to these fields if they are missing in the command from
// the user.
// @tags: [
//   # mapReduce does not support afterClusterTime.
//   does_not_support_causal_consistency,
//   does_not_support_stepdowns,
//   uses_map_reduce_with_temp_collections,
// ]
(function() {
"use strict";

const coll = db.mr_null_test;
const outColl = db.mr_null_test_out;
assert.commandWorked(coll.insert({val: 1}));

function mapFunc() {
    emit(this.val, 1);
}
function reduceFunc(k, v) {
    return Array.sum(v);
}

// Test that finalize can be explicit null.
assert.commandWorked(db.runCommand({
    mapReduce: coll.getName(),
    map: mapFunc,
    reduce: reduceFunc,
    finalize: null,
    out: {merge: outColl.getName()}
}));

// Test that query can be explicit null.
assert.commandWorked(db.runCommand({
    mapReduce: coll.getName(),
    map: mapFunc,
    reduce: reduceFunc,
    query: null,
    out: {merge: outColl.getName()}
}));

// Test that sort can be explicit null.
assert.commandWorked(db.runCommand({
    mapReduce: coll.getName(),
    map: mapFunc,
    reduce: reduceFunc,
    sort: null,
    out: {merge: outColl.getName()}
}));

// Test that scope can be explicit null.
assert.commandWorked(db.runCommand({
    mapReduce: coll.getName(),
    map: mapFunc,
    reduce: reduceFunc,
    scope: null,
    out: {merge: outColl.getName()}
}));
})();