Pipeline Practice

MongoDB $lookup

Join matching documents from another collection.

The joined matches are always placed in an array named by `as`. For a one-to-one relationship, `$unwind` that array before reading the joined fields.

Stages are the top-level steps in a pipeline. Each stage receives documents, changes the stream in one specific way, and passes its output to the next stage.

Course use: Exercises 10, 12, and Hard Mode 13.

Example pipeline syntax

{ $lookup: {
  from: "customers",
  localField: "customerId",
  foreignField: "_id",
  as: "customer"
} }