What do lookup, unwind and facet do?
Practice this questionWANT TO UNDERSTAND THE CONCEPT FIRST?Learn What do lookup, unwind and facet do?
Definition:
$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.
Key points:
-
$lookupadds matching data from another collection. -
$unwindturns array items into separate output documents. -
$facetproduces multiple grouped outputs, such as a page and a count. -
Unwinding an array of ten items can turn one document into ten; choose whether empty arrays should be preserved.
Interview point:
- Explain row multiplication and what it does to later counts or sums, not just the operator names.
Adapted from 04_MONGODB_MONGOOSE.md · “What do lookup, unwind and facet do?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.