-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.4.7, 3.5.11, 3.5.12
-
Component/s: Aggregation Framework
-
Labels:None
-
ALL
-
Both $sum and $avg are meant to act both as accumulators with $group as well as working with a provided array. A common usage would be to $filter array content and feed that to $avg to obtain the average for the array in the document and then "accumulate" those values with another $avg in a $group pipeline.
When used in the style of:
result: {
$avg: {
$avg: '$values'
}
}
This works as expected when the _id provided to $group accumulates more than one document. However if the provided property does not accumulate over more than one document, the value is returned as null.
This affects both $avg and $sum when applied as both accumulator and array reducer.