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, 27 insertions, 35 deletions
diff --git a/jstests/aggregation/bugs/groupMissing.js b/jstests/aggregation/bugs/groupMissing.js
index ba6b0f58fff..f13477a90b6 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 assertArrayEq.
+load('jstests/aggregation/extras/utils.js'); // For resultsEq.
(function() {
"use strict";
-const coll = db.getCollection(jsTestName());
+var coll = db.groupMissing;
coll.drop();
-assert.commandWorked(coll.insert({a: null}));
-assert.commandWorked(coll.insert({}));
+coll.insert({a: null});
+coll.insert({});
-let res = coll.aggregate({$group: {_id: "$a"}});
-let arr = res.toArray();
+var res = coll.aggregate({$group: {_id: "$a"}});
+var arr = res.toArray();
assert.eq(arr.length, 1);
assert.eq(arr[0]._id, null);
-assert.commandWorked(coll.createIndex({a: 1}));
+coll.createIndex({a: 1});
res = coll.aggregate({$sort: {a: 1}}, {$group: {_id: "$a"}});
arr = res.toArray();
assert.eq(arr.length, 1);
@@ -31,49 +31,41 @@ assert.eq(arr[0]._id, null);
coll.drop();
-assert.commandWorked(coll.insert({a: null}));
-assert.commandWorked(coll.insert({}));
+coll.insert({a: null});
+coll.insert({});
// Bug, see SERVER-21992.
res = coll.aggregate({$group: {_id: {a: "$a"}}});
-assertArrayEq({actual: res.toArray(), expected: [{_id: {a: null}}]});
+assert(resultsEq(res.toArray(), [{_id: {a: null}}]));
// Bug, see SERVER-21992.
-assert.commandWorked(coll.createIndex({a: 1}));
+coll.createIndex({a: 1});
res = coll.aggregate({$group: {_id: {a: "$a"}}});
-assertArrayEq({actual: res.toArray(), expected: [{_id: {a: null}}]});
+assert(resultsEq(res.toArray(), [{_id: {a: null}}]));
// Correct behavior after SERVER-21992 is fixed.
if (0) {
res = coll.aggregate({$group: {_id: {a: "$a"}}});
- assertArrayEq({actual: res.toArray(), expected: [{_id: {a: null}}, {_id: {}}]});
+ assert(resultsEq(res.toArray(), [{_id: {a: null}}, {_id: {}}]));
}
coll.drop();
-assert.commandWorked(coll.insert({a: null, b: 1}));
-assert.commandWorked(coll.insert({b: 1}));
-assert.commandWorked(coll.insert({a: null, b: 1}));
+coll.insert({a: null, b: 1});
+coll.insert({b: 1});
+coll.insert({a: null, b: 1});
res = coll.aggregate({$group: {_id: {a: "$a", b: "$b"}}});
-assertArrayEq({actual: res.toArray(), expected: [{_id: {b: 1}}, {_id: {a: null, b: 1}}]});
+assert(resultsEq(res.toArray(), [{_id: {b: 1}}, {_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}}]});
+// 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}}]));
-// 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()
-});
+// 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}}]));
+}
}());