Accumulator
noun
say it: “uh-KYOO-myuh-lay-ter” /əˈkjumjəˌleɪtər/
In a MongoDB $group stage, an operator such as $sum or $avg that combines one value from each document in a group into a single result.
What is an accumulator in a MongoDB $group stage?
An accumulator is an operator in a $group stage that takes one value from every document in a group and turns them into one answer: $sum adds, $avg averages, $min and $max find the smallest and largest, and $first keeps the first.
db.orders.aggregate([
{ $group: { _id: "$category", revenue: { $sum: "$total" }, biggest: { $max: "$total" } } }
]);
// [ { _id: 'bikes', revenue: 48210, biggest: 2899 }, ... ]
In a sentence
- “Each output field of $group needs an accumulator, such as $avg for the average order.”
- “The accumulator $sum added up every order's total in each category.”
Level: Journeyman · More MongoDB terms at this level
Updated