diff options
author | Jason Rassi <rassi@10gen.com> | 2015-04-06 13:20:21 -0400 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2015-04-09 13:24:58 -0400 |
commit | 4afe8edcb27537f6d2f13dd7ccae700cc3b4efb8 (patch) | |
tree | ad959463a85fc18ca2039a0b8c9c6c7e702641a8 | |
parent | 62ce3ed18a843b979d11fc70f730a81993979825 (diff) | |
download | mongo-4afe8edcb27537f6d2f13dd7ccae700cc3b4efb8.tar.gz |
SERVER-17889 MapReduceCommand::run() error out from DBDirectClient
(cherry picked from commit 93c8c001e4462a1f0c0eeed12901fadbdc1861d8)
-rw-r--r-- | jstests/core/eval_mr.js | 17 | ||||
-rw-r--r-- | src/mongo/db/commands/mr.cpp | 7 |
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 ); |