summaryrefslogtreecommitdiff
path: root/jstests/aggregation/bugs/groupMissing.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/aggregation/bugs/groupMissing.js')
-rw-r--r--jstests/aggregation/bugs/groupMissing.js62
1 files changed, 35 insertions, 27 deletions
diff --git a/jstests/aggregation/bugs/groupMissing.js b/jstests/aggregation/bugs/groupMissing.js
index f13477a90b6..ba6b0f58fff 100644
--- a/jstests/aggregation/bugs/groupMissing.js
+++ b/jstests/aggregation/bugs/groupMissing.js
@@ -7,23 +7,23 @@
// @tags: [
// do_not_wrap_aggregations_in_facets,
// ]
-load('jstests/aggregation/extras/utils.js'); // For resultsEq.
+load('jstests/aggregation/extras/utils.js'); // For assertArrayEq.
(function() {
"use strict";
-var coll = db.groupMissing;
+const coll = db.getCollection(jsTestName());
coll.drop();
-coll.insert({a: null});
-coll.insert({});
+assert.commandWorked(coll.insert({a: null}));
+assert.commandWorked(coll.insert({}));
-var res = coll.aggregate({$group: {_id: "$a"}});
-var arr = res.toArray();
+let res = coll.aggregate({$group: {_id: "$a"}});
+let arr = res.toArray();
assert.eq(arr.length, 1);
assert.eq(arr[0]._id, null);
-coll.createIndex({a: 1});
+assert.commandWorked(coll.createIndex({a: 1}));
res = coll.aggregate({$sort: {a: 1}}, {$group: {_id: "$a"}});
arr = res.toArray();
assert.eq(arr.length, 1);
@@ -31,41 +31,49 @@ assert.eq(arr[0]._id, null);
coll.drop();
-coll.insert({a: null});
-coll.insert({});
+assert.commandWorked(coll.insert({a: null}));
+assert.commandWorked(coll.insert({}));
// Bug, see SERVER-21992.
res = coll.aggregate({$group: {_id: {a: "$a"}}});
-assert(resultsEq(res.toArray(), [{_id: {a: null}}]));
+assertArrayEq({actual: res.toArray(), expected: [{_id: {a: null}}]});
// Bug, see SERVER-21992.
-coll.createIndex({a: 1});
+assert.commandWorked(coll.createIndex({a: 1}));
res = coll.aggregate({$group: {_id: {a: "$a"}}});
-assert(resultsEq(res.toArray(), [{_id: {a: null}}]));
+assertArrayEq({actual: res.toArray(), expected: [{_id: {a: null}}]});
// Correct behavior after SERVER-21992 is fixed.
if (0) {
res = coll.aggregate({$group: {_id: {a: "$a"}}});
- assert(resultsEq(res.toArray(), [{_id: {a: null}}, {_id: {}}]));
+ assertArrayEq({actual: res.toArray(), expected: [{_id: {a: null}}, {_id: {}}]});
}
coll.drop();
-coll.insert({a: null, b: 1});
-coll.insert({b: 1});
-coll.insert({a: null, b: 1});
+assert.commandWorked(coll.insert({a: null, b: 1}));
+assert.commandWorked(coll.insert({b: 1}));
+assert.commandWorked(coll.insert({a: null, b: 1}));
res = coll.aggregate({$group: {_id: {a: "$a", b: "$b"}}});
-assert(resultsEq(res.toArray(), [{_id: {b: 1}}, {_id: {a: null, b: 1}}]));
+assertArrayEq({actual: res.toArray(), expected: [{_id: {b: 1}}, {_id: {a: null, b: 1}}]});
-// Bug, see SERVER-23229.
-coll.createIndex({a: 1, b: 1});
-res = coll.aggregate({$sort: {a: 1, b: 1}}, {$group: {_id: {a: "$a", b: "$b"}}});
-assert(resultsEq(res.toArray(), [{_id: {a: null, b: 1}}]));
+assert.commandWorked(coll.createIndex({a: 1, b: 1}));
+res = coll.aggregate([{$group: {_id: {a: "$a", b: "$b"}}}, {$sort: {"_id.a": 1, "_id.b": 1}}]);
+// Before fixing SERVER-23229 we were getting [{_id: {a: null, b: 1}}]
+assertArrayEq({actual: res.toArray(), expected: [{_id: {b: 1}}, {_id: {a: null, b: 1}}]});
-// Correct behavior after SERVER-23229 is fixed.
-if (0) {
- coll.createIndex({a: 1, b: 1});
- res = coll.aggregate({$sort: {a: 1, b: 1}}, {$group: {_id: {a: "$a", b: "$b"}}});
- assert(resultsEq(res.toArray(), [{_id: {b: 1}}, {_id: {a: null, b: 1}}]));
-}
+// Try another variation of the query that is taken more directly from the bug report SERVER-23229.
+coll.drop();
+assert.commandWorked(coll.insert({a: 1, b: null}));
+assert.commandWorked(coll.insert({a: null, b: 1}));
+assert.commandWorked(coll.insert({b: 1}));
+assert.commandWorked(coll.insert({a: 1}));
+
+let preSortResult =
+ coll.aggregate({$sort: {a: 1, b: 1}}, {$group: {_id: {a: "$a", b: "$b"}}}).toArray();
+assert.commandWorked(coll.createIndex({a: 1, b: 1}));
+assertArrayEq({
+ actual: preSortResult,
+ expected: coll.aggregate({$group: {_id: {a: "$a", b: "$b"}}}).toArray()
+});
}());