From 126cecc6366342ffe9d4561ba6ff7532f596c019 Mon Sep 17 00:00:00 2001 From: Misha Tyulenev Date: Mon, 14 Dec 2015 19:19:03 -0500 Subject: [PATCH] SERVER-21706 error when mapReduce outputs to config or admin db (cherry picked from commit 3e1a3872c996fcc72c8cf20ea38e9fe86a11caa4) --- jstests/sharding/map_reduce_validation.js | 16 ++++++++++++++++ src/mongo/db/commands/mr.cpp | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/jstests/sharding/map_reduce_validation.js b/jstests/sharding/map_reduce_validation.js index f85c47f3831..9fe08edd91a 100644 --- a/jstests/sharding/map_reduce_validation.js +++ b/jstests/sharding/map_reduce_validation.js @@ -10,4 +10,20 @@ assert.commandFailed(testDB.runCommand({ mapReduce: 'user', reduce: reduceFunc, out: { inline: 1, sharded: true }})); +testDB.bar.insert({i: 1}); +assert.commandFailed(testDB.runCommand({ mapReduce: 'bar', + map: function() {emit(this.i, this.i*3);}, + reduce: function(key, values) {return Array.sum(values)}, + out: { replace: "foo", db: "admin" }})); + +assert.commandFailed(testDB.runCommand({ mapReduce: 'bar', + map: function() {emit(this.i, this.i*3);}, + reduce: function(key, values) {return Array.sum(values)}, + out: { replace: "foo", db: "config" }})); + +assert.commandWorked(testDB.runCommand({ mapReduce: 'bar', + map: function() {emit(this.i, this.i*3);}, + reduce: function(key, values) {return Array.sum(values)}, + out: { replace: "foo", db: "test" }})); + st.stop(); diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index 2d050c924f1..d0066e7e066 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -1566,6 +1566,14 @@ public: int, string& errmsg, BSONObjBuilder& result) { + if (!grid.shardRegistry()) { + return appendCommandStatus( + result, + Status(ErrorCodes::CommandNotSupported, + str::stream() << "Can not execute mapReduce with output database " + << dbname)); + } + boost::optional maybeDisableValidation; if (shouldBypassDocumentValidationForCommand(cmdObj)) maybeDisableValidation.emplace(txn);