diff options
Diffstat (limited to 'jstests')
| -rw-r--r-- | jstests/aggregation/sources/group/group_by_empty_object.js | 19 | ||||
| -rw-r--r-- | jstests/aggregation/sources/group/group_by_variable.js | 5 |
2 files changed, 21 insertions, 3 deletions
diff --git a/jstests/aggregation/sources/group/group_by_empty_object.js b/jstests/aggregation/sources/group/group_by_empty_object.js new file mode 100644 index 00000000000..1dc64a6ee1c --- /dev/null +++ b/jstests/aggregation/sources/group/group_by_empty_object.js @@ -0,0 +1,19 @@ +/* + * Test that $group works when an empty object is passed for _id. This is intended to reproduce + * SERVER-89611. + */ +const coll = db.group_by_empty_obj; +coll.drop(); + +assert.commandWorked(coll.insert([{_id: 1, x: 1}, {_id: 2, x: 2}])); + +function assertIsEmptyObjId(groupSpec) { + assert.eq([{_id: {}}], coll.aggregate([groupSpec]).toArray()); +} +assertIsEmptyObjId({$group: {_id: {}}}); +assertIsEmptyObjId({$group: {_id: {$expr: {}}}}); +assertIsEmptyObjId({$group: {_id: {$expr: {$const: {}}}}}); +assertIsEmptyObjId({$group: {_id: {$expr: {$expr: {}}}}}); + +// The original fuzzer failure involved a $sortByCount query +assert.eq([{_id: {}, count: 2}], coll.aggregate([{$sortByCount: {$expr: {}}}]).toArray()); diff --git a/jstests/aggregation/sources/group/group_by_variable.js b/jstests/aggregation/sources/group/group_by_variable.js index ef08d7bb91b..f306a8eabd0 100644 --- a/jstests/aggregation/sources/group/group_by_variable.js +++ b/jstests/aggregation/sources/group/group_by_variable.js @@ -5,8 +5,7 @@ const coll = db.group_by_system_var; coll.drop(); -assert.commandWorked(coll.insert({_id: 1, x: 1})); -assert.commandWorked(coll.insert({_id: 2, x: 2})); +assert.commandWorked(coll.insert([{_id: 1, x: 1}, {_id: 2, x: 2}])); function checkPipeline(pipeline, expectedResults) { const res = coll.aggregate(pipeline).toArray(); @@ -19,4 +18,4 @@ checkPipeline([{$group: {_id: "$$CURRENT"}}, {$sort: {"_id": 1}}], wholeCollUnde const collIds = [{_id: 1}, {_id: 2}]; checkPipeline([{$group: {_id: "$$ROOT.x"}}, {$sort: {"_id": 1}}], collIds); -checkPipeline([{$group: {_id: "$$CURRENT.x"}}, {$sort: {"_id": 1}}], collIds);
\ No newline at end of file +checkPipeline([{$group: {_id: "$$CURRENT.x"}}, {$sort: {"_id": 1}}], collIds); |
