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
|
// Tests that multi-line strings with comments are allowed within mapReduce.
// @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_comments;
coll.drop();
const outColl = db.mr_comments_out;
outColl.drop();
assert.commandWorked(coll.insert([{foo: 1}, {foo: 1}, {foo: 2}]));
// Test using comments within the function.
assert.commandWorked(db.runCommand({
mapreduce: coll.getName(),
map: "// This is a comment\n\n // Emit some stuff\n emit(this.foo, 1)\n",
reduce: function(key, values) {
return Array.sum(values);
},
out: {merge: outColl.getName()}
}));
assert.eq(2, outColl.find().toArray().length);
// Test using a multi-line string literal.
outColl.drop();
assert.commandWorked(db.runCommand({
mapreduce: coll.getName(),
map: `
// This is a comment
// Emit some stuff
emit(this.foo, 1);
`,
reduce: function(key, values) {
return Array.sum(values);
},
out: {merge: outColl.getName()}
}));
assert.eq(2, outColl.find().toArray().length);
// Test that a function passed with a comment in front of it is still recognized.
outColl.drop();
assert.commandWorked(db.runCommand({
mapreduce: coll.getName(),
map: "// This is a comment\nfunction(){\n // Emit some stuff\n emit(this.foo, 1)\n}\n",
reduce: function(key, values) {
return Array.sum(values);
},
out: {merge: outColl.getName()}
}));
assert.eq(2, outColl.find().toArray().length);
}());
|