Back to MongoDB Notes
Topic #20

$lookup


Aggregation $lookup

This aggregation stage performs a left outer join to a collection in the same database.

There are four required fields:

  • from: The collection to use for lookup in the same database
  • localField: The field in the primary collection that can be used as a unique identifier in the from collection.
  • foreignField: The field in the from collection that can be used as a unique identifier in the primary collection.
  • as: The name of the new field that will contain the matching documents from the from collection.

Example

db.comments.aggregate([
  {
    $lookup: {
      from: "movies",
      localField: "movie_id",
      foreignField: "_id",
      as: "movie_details",
    },
  },
  {
    $limit: 1
  }
])

This will return the movie data along with each comment.

Want to go beyond the notes?

Join Coding Now Tech Institute's MongoDB course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

$lookup – FAQs

Quick answers about learning $lookup in MongoDB.

This free note from Coding Now Tech Institute explains $lookup in MongoDB — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every MongoDB topic on Coding Now Tech Institute, including $lookup, is 100% free with no signup required.
With focused practice, most students grasp $lookup in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now