The members of a collection are passed through a pipeline to produce a result. Expressions Computed values (fields & operators). Document format using prefixes.
in the context of their surrounding documents. • Multiple documents can be generated from a single source document. • Nothing for absent or empty array. • Error for non-array fields.
(_id): • single field • document • constant value Other fields are computed: $sum, $avg, $min, $max, $first, $last, $push, $addToSet (no sub-documents allowed)
scanning the entire collection). Sorting: $sort operator can take advantage of an index when placed at the beginning of the pipeline or placed before the following aggregation operators: $project, $unwind, $group. Op'miza'on
to $group or $sort to shards; • merges $sort and $group results; • processes remaining operations. Early $match can exclude shards. Required more CPU resources.
{$group: { _id: “$city”, count: {$sum: 1}}}, {$match: { count: {$lt: 10000}}}, {$sort: { adult_count: -1}}, {$project: { _id: 0, city: “$_id”, adult_count: “$count”}}]); select - $project where/having - $match group by - $group order by - $sort select city, count(id) from users where age >= 16 group by city having count(id) < 10000 order by 2 desc