Aggregation Operators in MongoDB
From the MongoDB cheat sheet ยท Aggregation Pipeline ยท verified Jul 2026
Aggregation Operators
Operators for calculations and transformations
javascript
// Group accumulator operators
db.sales.aggregate([
{ $group: {
_id: "$category",
total: { $sum: "$amount" },
average: { $avg: "$amount" },
min: { $min: "$amount" },
max: { $max: "$amount" },
count: { $sum: 1 },
items: { $push: "$item" },
uniqueItems: { $addToSet: "$item" }
}}
])
// String operators
{ $project: {
upper: { $toUpper: "$name" },
lower: { $toLower: "$name" },
substring: { $substr: ["$name", 0, 3] },
concat: { $concat: ["$first", " ", "$last"] }
}}๐ก $sum: 1 counts documents
๐ Use $$ for variables in expressions
โก $cond for if-then-else logic
๐ข Essential for data analysis
๐ Related: $map, $reduce for array processing
aggregationoperators