$project
Reference group: Pipeline stages
What it does
Includes/excludes fields and computes values.
Syntax
{$project: { field: 1, computed: expression }}
Use case
Shape response/report output.
Important notes
Inclusion/exclusion combinations have rules; _id is a common exception.
$project: practical example
{ $project: { orderNumber: 1, total: 1, tax: { $multiply: ["$total", 0.18] } } }💡 Explanation
Includes/excludes fields and computes values.
When to use it
Shape response/report output.
Caution
Inclusion/exclusion combinations have rules;
_id is a common exception.Key Takeaways
- Includes/excludes fields and computes values.
- Typical use: Shape response/report output.