summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/mr_single_reduce_optimization.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthrough/mr_single_reduce_optimization.js')
-rw-r--r--jstests/noPassthrough/mr_single_reduce_optimization.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/jstests/noPassthrough/mr_single_reduce_optimization.js b/jstests/noPassthrough/mr_single_reduce_optimization.js
new file mode 100644
index 00000000000..71ab924836b
--- /dev/null
+++ b/jstests/noPassthrough/mr_single_reduce_optimization.js
@@ -0,0 +1,29 @@
+(function() {
+"use strict";
+// See SERVER-68766. Verify that the reduce function is not run on a single value if the relevant
+// flag is enabled.
+
+const conn = MongoRunner.runMongod({setParameter: {mrEnableSingleReduceOptimization: true}});
+const testDB = conn.getDB('foo');
+const coll = testDB.bar;
+
+assert.commandWorked(coll.insert({x: 1}));
+
+const map = function() {
+ emit(0, "mapped value");
+};
+
+const reduce = function(key, values) {
+ return "reduced value";
+};
+
+let res = assert.commandWorked(
+ testDB.runCommand({mapReduce: 'bar', map: map, reduce: reduce, out: {inline: 1}}));
+assert.eq(res.results[0], {_id: 0, value: "mapped value"});
+assert.commandWorked(coll.insert({x: 2}));
+res = assert.commandWorked(
+ testDB.runCommand({mapReduce: 'bar', map: map, reduce: reduce, out: {inline: 1}}));
+assert.eq(res.results[0], {_id: 0, value: "reduced value"});
+
+MongoRunner.stopMongod(conn);
+}());