Details
-
Improvement
-
Resolution: Unresolved
-
Major - P3
-
None
-
None
-
Query Execution
-
Query 2020-08-24
Description
The $avg pipeline group accumulator computes the average by summing all elements then divide by the count.
src/mongo/db/pipeline/accumulator_avg.cpp :
return Value(_nonDecimalTotal.getDouble() / static_cast<double>(_count));
|
This may lead to an overflow in the sum for large number of records or large numbers.
To be evaluated for performance reasons : using a stream-average to compute the average.
count++
|
avg += (x - avg) / count;
|