Aggregation accumulators

Accumulators are probably the most widely used operators, as they allow us to sum, average, get standard deviation statistics, and perform other operations in each member of our group. The following is a list of the aggregation accumulators:

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

These accumulators are available in the group or project pipeline phases except where otherwise noted.

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

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