$group
An aggregation pipeline stage that groups documents by a specified expression and applies accumulator operators.
Syntax
mongodb
{ $group: { _id: expression, field: { $accumulator: expr } } }Example
mongodb
db.sales.aggregate([
{ $group: {
_id: "$category",
total: { $sum: "$price" },
avg: { $avg: "$price" },
count: { $sum: 1 },
items: { $push: "$name" }
}}
])