-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.4.3
-
Component/s: Aggregation Framework
-
None
-
Fully Compatible
-
Quint Iteration 7, QuInt 8 08/28/15
Make the following accumulators available as expressions: $stdDevSamp, $stdDevPop, $avg, $min, $max, and $sum.
As expressions, available in the $project stage, these operators can take either:
- A single argument: <accumulator> : <arg>
- Multiple arguments: <accumulator> : [ <arg1>, <arg2>, ... ]
Single Argument: <arg>
If the argument is an array, the accumulator operates on the elements of the array to return a single value. If the argument is not an array, the accumulator operates on the single argument.
Multiple arguments: [ <arg1>, <arg2>, ... ]
The accumulator operates on the arguments to return a single value.
If any of the argments is an array, the accumulator does not traverse into the array elements.
Non-numerical arguments
When used as part of the $project stage, $sum, $avg, $stdDevSamp, and $stdDevPop ignore non-numerical arguments.
Original request:
{'$group': { '_id': { 'grp_0': '$ses.usr', 'grp_1': '$ses._id' }, 'agg_0': {'$sum': {'$subtract': [ {'$cond': [{'$lt': ['$ses.e', E]}, '$ses.e', E]}, {'$cond': [{'$gt': ['$ses.s', S]}, '$ses.s', S]} ]} } }}
you can write:
{'$group': { '_id': { 'grp_0': '$ses.usr', 'grp_1': '$ses._id' }, 'agg_0': {'$sum': {'$subtract': [ {'$min': ['$ses.e', E]}, {'$max': ['$ses.s', S]} ]} } } }
- is duplicated by
-
SERVER-10626 Support numeric arrays as input to $add in aggregation's $project
- Closed
-
SERVER-14359 Allow $max, $min, $avg calculations in $project.
- Closed
-
SERVER-19166 $stdDev should be available as an expression as well as an accumulator
- Closed
-
SERVER-14565 New aggregation operators
- Closed
- is related to
-
DRIVERS-234 Aggregation Builder Support for 3.2
- Closed
- related to
-
CSHARP-1373 Support many accumulators in aggregation framework as expressions
- Closed