-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Fully Compatible
-
ALL
-
v7.0, v6.0
-
QE 2023-06-12
-
164
For sharded collection, the following query gives incorrect results:
coll.aggregate([{$group: {_id: null, result: {$topN: {n: 3, output: "abc", sortBy: {}}}}}])
This is a pretty useless query. However, the results from both Classic engine and SBE are incorrect:
{ "_id" : null, "result" : [ { "output" : "abc", "sortFields" : [ ] }, { "output" : "abc", "sortFields" : [ ] }, { "output" : "abc", "sortFields" : [ ] } ] }
This is due to the erroneous logic for serializing constant argument: https://github.com/10gen/mongo/blob/c6b787ec1d8cc77b3ae09fda85e278cd6e752ee6/src/mongo/db/pipeline/accumulator_multi.cpp#L473
When the argument is constant, the serialized value will be {$const: {output: ...}} instead of
{output: ...}, so the logic to distinguish merging group is wrong and the output field is appended incorrectly.