Aggregation accumulators

Accumulators are probably the most widely used operators, allowing us to sum, average, get standard deviation statistics, and perform other operations in each member of our group.

  • $sum is the sum of numerical values, ignores non-numerical values
  • $avg is the average of numerical values, ignores non-numerical values
  • $first / $last is the first and last value that passes through the pipeline stage, available in the group stage only
  • $max / $min gets the maximum and minimum value that passes through the pipeline stage
  • $push, will add a new element at the end of an input array, available in the group stage only
  • $addToSet, will add an element (only if it does not exist) to an array treating it effectively as a set, available in the group stage only
  • $stdDevPop / $stdDevSamp to get the population / sample standard deviation in the $project or $match stages

The aforementioned mentioned accumulators are available in the group or project pipeline phases except otherwise noted.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.30.236