MongoDB & MongooseInterview preparation
Intermediate·Concept·2 min read

What do lookup, unwind and facet do?

Practice this question

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:

  • $lookup adds matching data from another collection.

  • $unwind turns array items into separate output documents.

  • $facet produces 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.