summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/mr.cpp10
-rw-r--r--src/mongo/db/commands/mr.h1
-rw-r--r--src/mongo/db/commands/mr_test.cpp39
3 files changed, 50 insertions, 0 deletions
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 155525578ee..b0898b1064a 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -336,6 +336,16 @@ Config::Config(const string& _dbname, const BSONObj& cmdObj) {
else
uassert(13609, "sort has to be blank or an Object", !s.trueValue());
+ BSONElement collationElt = cmdObj["collation"];
+ if (collationElt.type() == Object)
+ collation = collationElt.embeddedObjectUserCheck();
+ else
+ uassert(40082,
+ str::stream()
+ << "mapReduce 'collation' parameter must be of type Object but found type: "
+ << typeName(collationElt.type()),
+ collationElt.eoo());
+
if (cmdObj["limit"].isNumber())
limit = cmdObj["limit"].numberLong();
else
diff --git a/src/mongo/db/commands/mr.h b/src/mongo/db/commands/mr.h
index 3d967438179..3237e6f7238 100644
--- a/src/mongo/db/commands/mr.h
+++ b/src/mongo/db/commands/mr.h
@@ -206,6 +206,7 @@ public:
BSONObj filter;
BSONObj sort;
+ BSONObj collation;
long long limit;
// functions
diff --git a/src/mongo/db/commands/mr_test.cpp b/src/mongo/db/commands/mr_test.cpp
index 93e90851257..d58ca5326f2 100644
--- a/src/mongo/db/commands/mr_test.cpp
+++ b/src/mongo/db/commands/mr_test.cpp
@@ -208,4 +208,43 @@ TEST(ConfigOutputOptionsTest, parseOutputOptions) {
mr::Config::INMEMORY);
}
+TEST(ConfigTest, ParseCollation) {
+ std::string dbname = "myDB";
+ BSONObj collation = BSON("locale"
+ << "en_US");
+ BSONObjBuilder bob;
+ bob.append("mapReduce", "myCollection");
+ bob.appendCode("map", "function() { emit(0, 1); }");
+ bob.appendCode("reduce", "function(k, v) { return {count: 0}; }");
+ bob.append("out", "outCollection");
+ bob.append("collation", collation);
+ BSONObj cmdObj = bob.obj();
+ mr::Config config(dbname, cmdObj);
+ ASSERT_EQUALS(config.collation, collation);
+}
+
+TEST(ConfigTest, ParseNoCollation) {
+ std::string dbname = "myDB";
+ BSONObjBuilder bob;
+ bob.append("mapReduce", "myCollection");
+ bob.appendCode("map", "function() { emit(0, 1); }");
+ bob.appendCode("reduce", "function(k, v) { return {count: 0}; }");
+ bob.append("out", "outCollection");
+ BSONObj cmdObj = bob.obj();
+ mr::Config config(dbname, cmdObj);
+ ASSERT_EQUALS(config.collation, BSONObj());
+}
+
+TEST(ConfigTest, CollationNotAnObjectFailsToParse) {
+ std::string dbname = "myDB";
+ BSONObjBuilder bob;
+ bob.append("mapReduce", "myCollection");
+ bob.appendCode("map", "function() { emit(0, 1); }");
+ bob.appendCode("reduce", "function(k, v) { return {count: 0}; }");
+ bob.append("out", "outCollection");
+ bob.append("collation", "en_US");
+ BSONObj cmdObj = bob.obj();
+ ASSERT_THROWS(mr::Config(dbname, cmdObj), UserException);
+}
+
} // namespace