summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/core/eval_mr.js17
-rw-r--r--src/mongo/db/commands/mr.cpp7
2 files changed, 24 insertions, 0 deletions
diff --git a/jstests/core/eval_mr.js b/jstests/core/eval_mr.js
new file mode 100644
index 00000000000..84a929035d6
--- /dev/null
+++ b/jstests/core/eval_mr.js
@@ -0,0 +1,17 @@
+// Test that the eval command can't be used to invoke the mapReduce command. SERVER-17889.
+(function() {
+ "use strict";
+ db.eval_mr.drop();
+ db.eval_mr_out.drop();
+ assert.writeOK(db.eval_mr.insert({val: 1}));
+ assert.writeOK(db.eval_mr.insert({val: 2}));
+ var runBasicMapReduce = function() {
+ return db.eval_mr.runCommand("mapReduce",
+ {map: function() { emit(0, this.val); },
+ reduce: function(id, values) { return Array.sum(values); },
+ out: {replace: "eval_mr_out"}});
+ };
+ assert.commandWorked(runBasicMapReduce());
+ assert.eq(3, db.eval_mr_out.findOne().value);
+ assert.commandFailed(db.eval(runBasicMapReduce));
+})();
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 3a0d2aa048e..057dfb1b5b4 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -1271,6 +1271,13 @@ namespace mongo {
bool run(OperationContext* txn, const string& dbname , BSONObj& cmd, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
Timer t;
+
+ if (txn->getClient()->isInDirectClient()) {
+ return appendCommandStatus(result,
+ Status(ErrorCodes::IllegalOperation,
+ "Cannot run mapReduce command from eval()"));
+ }
+
CurOp* op = txn->getCurOp();
Config config( dbname , cmd );