Accumulator Operators

OperatorDescriptionExample
$countPerforms a count of a grouped documents or, if the property is an array, a count of the number of elements.{“numInGroup”: {“$count”: “_id”}}
$sumCalculates the sum of a number property or expression in the group.{“sumOfDays”: {“$sum”: {“$dayOfMonth”: “created”}}}
$avgCalculates the average of a number property or expression in the group.{“averageHeartRate”: {“$avg”: “c_bpm”}}
$firstReturns the first value from the group. The result depends on the sort field(s).{“oldest”: {“$first”: “created”}}
$lastReturns the last value from the group. The result depends on the sort field(s).{“latest”: {“$last”: “created”}}
$minReturns the smallest value from the group.{“smallest”: {“$min”: “c_size”}}
$maxReturns the largest value from the group.{“largestArray”: {“$max: {”$size": “c_arr”}}}
$pushAllReturns the array of pushed values, with NULL included in the array where there are missing values{"combinedArray": {"$pushAll": "c_value"}}
$pushReturns the array of pushed values{"combinedArray": {"$push": "c_value"}}
$addToSetReturns array of unique pushed values{"uniqueArray": {"$addToSet": "c_value"}}
$stdDevPopReturns the population standard deviation of input values{"stdDeviation": { "$stdDevPop": "c_heartrate"}}
$stdDevSampReturns the sample standard deviation of input values{"stdDeviation": { "$stdDevSamp": "c_heartrate"}}