Database IntegrationLesson 70Free preview
MongoDB Join
This lesson is part of Node.js · All levels
Summary
This lesson introduces $lookup, the way MongoDB combines a collection similar to JOIN in SQL. You'll pull the order data and user profiles into one pipeline aggregation. In addition to $lookup, there is $unwind available to unpack the join result array for easy processing.
Key points
- $lookup is the aggregation stage of the collection combining from, localField, foreignField, and as.
- After $lookup, the resulting field is an array (although only one match).
- $unwind expands the resulting array to one row per element.
- $project filters the column so the pipeline doesn't load large documents repeatedly.
- $lookup with let/pipeline supports additional conditions (filtered lookup).
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.