How does the $lookup operator work?

Updated May 1, 2026

Short answer

$lookup performs a join between two collections in the same database.

Deep explanation

It takes 'from' (target collection), 'localField', 'foreignField', and 'as' (output array name). It's a powerful tool for relational-like queries.

Real-world example

Fetching user details alongside their order history.

Common mistakes

  • Using $lookup on unindexed foreign fields, causing slow joins.

Follow-up questions

  • Can you join across databases?

More MongoDB interview questions

View all →