1.Aggregation expression categories
Aggregation expressions are the functions you use inside $project, $set, $group and other stages to compute a value from a document's fields, instead of just copying them through. They are grouped by what they work on: numbers, comparisons, strings, dates, arrays, and so on.
Key features
- Every expression operator starts with $ and can be nested inside another expression
- Arithmetic: $add, $subtract, $multiply, $divide, $mod
- Comparison: $eq, $gt, $lt, and friends — same names as query operators, different context
- Boolean: $and, $or, $not
- String: $concat, $toUpper, $toLower, $substrCP, $trim
- Array, conditional, object and conversion each have their own dedicated concept later in this section
Expression families and where each is used
Command
{ $operator: <expression> } or { $operator: [<expression>, ...] }Expression operators ($add, $concat, $gt, …) are the pipeline's formula language — they compute a value inside a stage, and nest inside each other like function calls.