MongoDB & Mongoose
Document modeling, aggregation, indexes, and consistency.
How does an aggregation pipeline work?
An aggregation pipeline transforms documents through an ordered series of stages. Each stage filters, reshapes, groups or combines the previous output, allowing reporting work to run close to the data. Stage order matters for both the meaning of the result and the amount of work required.
What do lookup, unwind and facet do?
$lookup adds related data from another collection, $unwind expands an array into individual output records, and $facet runs multiple sub-pipelines on the same input. These operations change the shape or number of documents flowing through a pipeline. They are useful for joins and reports but can increase memory use and intermediate result size.
What do set, addFields, skip and count do?
These stages shape or limit pipeline output: $set/$addFields create or replace fields, $skip removes a leading number of results, and $count summarizes how many documents remain. Their position determines whether they operate on source records or already transformed results. A small final result does not mean the earlier work was small.
Difficulty is an editorial estimate. Completion means you chose to mark a question as understood.