🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
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 CodingNow 2.0'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 CodingNow 2.0 explains $lookup in MongoDB — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every MongoDB topic on CodingNow 2.0, 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 CodingNow 2.0'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 CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now