summaryrefslogtreecommitdiff
path: root/jstests/aggregation
diff options
context:
space:
mode:
authorTed Tuckman <ted.tuckman@mongodb.com>2019-09-30 20:18:43 +0000
committerevergreen <evergreen@mongodb.com>2019-09-30 20:18:43 +0000
commit8e981e8315ab7c7bae93da623e40ffdce5b4ec6e (patch)
tree414f5e236cff2158456acb21ac12668d65c6e475 /jstests/aggregation
parent344e1b0f3ce5caf0d4760dddc8b2d196d4b73fe8 (diff)
downloadmongo-8e981e8315ab7c7bae93da623e40ffdce5b4ec6e.tar.gz
SERVER-42835 Fix inconsistent handling of arrays as $group keys
Diffstat (limited to 'jstests/aggregation')
-rw-r--r--jstests/aggregation/sources/group/group_key_is_array.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/jstests/aggregation/sources/group/group_key_is_array.js b/jstests/aggregation/sources/group/group_key_is_array.js
new file mode 100644
index 00000000000..90d7619ce39
--- /dev/null
+++ b/jstests/aggregation/sources/group/group_key_is_array.js
@@ -0,0 +1,17 @@
+/**
+ * Tests that a group _id with an array is evaluated whether it is at the top level or
+ * nested.
+ */
+(function() {
+"use strict";
+
+const coll = db.group_with_arrays;
+coll.drop();
+
+assert.commandWorked(coll.insert([{x: null}, {y: null}, {x: null, y: null}]));
+
+const arr_result = coll.aggregate([{$group: {_id: ["$x", "$y"]}}]);
+const nested_result = coll.aggregate([{$group: {_id: {z: ["$x", "$y"]}}}]);
+
+assert.eq(arr_result.toArray()[0]["_id"], nested_result.toArray()[0]["_id"]["z"]);
+}());