summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2016-04-20 13:47:08 -0400
committerTess Avitabile <tess.avitabile@mongodb.com>2016-04-22 09:34:25 -0400
commit53488b20e2fd51f1013d688673a6c1404c496200 (patch)
treebdb53521bd07f91e62d6cb092ca3232773971b80
parentcb6298ef61165e06474995b1a22eb18850246271 (diff)
downloadmongo-53488b20e2fd51f1013d688673a6c1404c496200.tar.gz
SERVER-23473 Add collation parameter to the group command
-rw-r--r--src/mongo/db/commands/group_cmd.cpp11
-rw-r--r--src/mongo/db/exec/group.h4
2 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/db/commands/group_cmd.cpp b/src/mongo/db/commands/group_cmd.cpp
index 60eeac1feb7..ba0bfa49740 100644
--- a/src/mongo/db/commands/group_cmd.cpp
+++ b/src/mongo/db/commands/group_cmd.cpp
@@ -28,6 +28,7 @@
#include "mongo/platform/basic.h"
+#include "mongo/bson/util/bson_extract.h"
#include "mongo/db/auth/action_set.h"
#include "mongo/db/auth/action_type.h"
#include "mongo/db/auth/authorization_session.h"
@@ -227,6 +228,16 @@ private:
// No key specified. Use the entire object as the key.
}
+ BSONElement collationElt;
+ Status collationEltStatus =
+ bsonExtractTypedField(p, "collation", BSONType::Object, &collationElt);
+ if (!collationEltStatus.isOK() && (collationEltStatus != ErrorCodes::NoSuchKey)) {
+ return collationEltStatus;
+ }
+ if (collationEltStatus.isOK()) {
+ request->collation = collationElt.embeddedObject().getOwned();
+ }
+
BSONElement reduce = p["$reduce"];
if (reduce.eoo()) {
return Status(ErrorCodes::BadValue, "$reduce has to be set");
diff --git a/src/mongo/db/exec/group.h b/src/mongo/db/exec/group.h
index 4199bc20cd5..355cab91b9d 100644
--- a/src/mongo/db/exec/group.h
+++ b/src/mongo/db/exec/group.h
@@ -54,6 +54,10 @@ struct GroupRequest {
// Empty is "keyPattern" is being used instead.
std::string keyFunctionCode;
+ // The collation used for string comparisons. If empty, simple binary comparison with memcmp()
+ // is used.
+ BSONObj collation;
+
// A Javascript function that takes a (input document, group result) pair and
// updates the group result document.
std::string reduceCode;