$match, $project and $addFields
$match filters early, $project chooses or renames fields and $addFields adds computed fields. Put $match first so indexes help.
Example
db.orders.aggregate([
{ $match: { amount: { $gt: 100 } } },
{ $addFields: { tax: { $multiply: ["$amount", 0.075] } } },
{ $project: { amount: 1, tax: 1, _id: 0 } }
])Exercise
Computed field.
{ $: { tax: 5 } }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.