summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Evans <jacob.evans@mongodb.com>2019-11-04 19:54:42 +0000
committerevergreen <evergreen@mongodb.com>2019-11-04 19:54:42 +0000
commit63b328413f488db299e729536ef123c5f0ba088d (patch)
treed082005c5c2a44fcd517612a5421e2b9723a59f3
parent0f7d49f67f1597f1411a092280c4c6c497d8bf12 (diff)
downloadmongo-63b328413f488db299e729536ef123c5f0ba088d.tar.gz
SERVER-44287 Update MR parser to be more permissive
-rw-r--r--src/mongo/db/commands/map_reduce.idl4
-rw-r--r--src/mongo/db/commands/map_reduce_out_options.cpp16
-rw-r--r--src/mongo/db/commands/map_reduce_parse_test.cpp71
3 files changed, 89 insertions, 2 deletions
diff --git a/src/mongo/db/commands/map_reduce.idl b/src/mongo/db/commands/map_reduce.idl
index ceb11f3f258..8c16042bf45 100644
--- a/src/mongo/db/commands/map_reduce.idl
+++ b/src/mongo/db/commands/map_reduce.idl
@@ -113,3 +113,7 @@ commands:
collection's document validation."
type: bool
optional: true
+ jsMode:
+ description: "Deprecated non-functional option which is ignored."
+ type: bool
+ optional: true
diff --git a/src/mongo/db/commands/map_reduce_out_options.cpp b/src/mongo/db/commands/map_reduce_out_options.cpp
index d1fed0f2626..aac1bdb1edb 100644
--- a/src/mongo/db/commands/map_reduce_out_options.cpp
+++ b/src/mongo/db/commands/map_reduce_out_options.cpp
@@ -52,14 +52,16 @@ MapReduceOutOptions MapReduceOutOptions::parseFromBSON(const BSONElement& elemen
return MapReduceOutOptions(boost::none, "", OutputType::InMemory, false);
}
- int allowedNFields = 3;
+ int allowedNFields = 4;
const auto sharded = [&]() {
if (const auto sharded = obj["sharded"]) {
uassert(ErrorCodes::BadValue,
"sharded field value must be boolean",
sharded.type() == Bool);
- return sharded.boolean();
+ uassert(
+ ErrorCodes::BadValue, "sharded field value must be true", sharded.boolean());
+ return true;
} else {
--allowedNFields;
return false;
@@ -100,6 +102,16 @@ MapReduceOutOptions MapReduceOutOptions::parseFromBSON(const BSONElement& elemen
}
}();
+ if (const auto nonAtomic = obj["nonAtomic"]) {
+ uassert(ErrorCodes::BadValue,
+ "nonAtomic field value must be boolean",
+ nonAtomic.type() == Bool);
+ uassert(
+ ErrorCodes::BadValue, "nonAtomic field value must be true", nonAtomic.boolean());
+ } else {
+ --allowedNFields;
+ }
+
uassert(ErrorCodes::BadValue,
"'out' supports only output type with collection name, optional 'sharded' and "
"optional 'db'",
diff --git a/src/mongo/db/commands/map_reduce_parse_test.cpp b/src/mongo/db/commands/map_reduce_parse_test.cpp
index d0bda49d84d..fc7f7e1ae9d 100644
--- a/src/mongo/db/commands/map_reduce_parse_test.cpp
+++ b/src/mongo/db/commands/map_reduce_parse_test.cpp
@@ -176,5 +176,76 @@ TEST(MapReduceParseTest, parseAllOptionalFields) {
<< "db"));
}
+TEST(MapReduceParseTest, deprecatedOptions) {
+ auto ctx = IDLParserErrorContext("mapReduce");
+ // jsMode can be true or false
+ MapReduce::parse(ctx,
+ BSON("mapReduce"
+ << "theSource"
+ << "map" << mapJavascript << "reduce" << reduceJavascript << "out"
+ << BSON("inline" << 1) << "$db"
+ << "db"
+ << "jsMode" << true));
+ MapReduce::parse(ctx,
+ BSON("mapReduce"
+ << "theSource"
+ << "map" << mapJavascript << "reduce" << reduceJavascript << "out"
+ << BSON("inline" << 1) << "$db"
+ << "db"
+ << "jsMode" << false));
+ // nonAtomic can be true but not false
+ MapReduce::parse(ctx,
+ BSON("mapReduce"
+ << "theSource"
+ << "map" << mapJavascript << "reduce" << reduceJavascript << "out"
+ << BSON("reduce"
+ << "theSink"
+ << "db"
+ << "myDb"
+ << "nonAtomic" << true)
+ << "$db"
+ << "db"));
+ ASSERT_THROWS(
+ MapReduce::parse(ctx,
+ BSON("mapReduce"
+ << "theSource"
+ << "map" << mapJavascript << "reduce" << reduceJavascript << "out"
+ << BSON("reduce"
+ << "theSink"
+ << "db"
+ << "myDb"
+ << "nonAtomic" << false)
+ << "$db"
+ << "db")),
+ DBException);
+ ASSERT_THROWS(
+ MapReduce::parse(ctx,
+ BSON("mapReduce"
+ << "theSource"
+ << "map" << mapJavascript << "reduce" << reduceJavascript << "out"
+ << BSON("reduce"
+ << "theSink"
+ << "db"
+ << "myDb"
+ << "nonAtomic" << false)
+ << "$db"
+ << "db")),
+ DBException);
+ // out.sharded cannot be false
+ ASSERT_THROWS(
+ MapReduce::parse(ctx,
+ BSON("mapReduce"
+ << "theSource"
+ << "map" << mapJavascript << "reduce" << reduceJavascript << "out"
+ << BSON("reduce"
+ << "theSink"
+ << "db"
+ << "myDb"
+ << "sharded" << false)
+ << "$db"
+ << "db")),
+ DBException);
+}
+
} // namespace
} // namespace mongo