Use `$lookup` for collection-to-collection joins.
Section: Core stages
Join with another collection
javascript
javascript
db.orders.aggregate([
{
$lookup: {
from: "users",
localField: "user_id",
foreignField: "_id",
as: "user"
}
},
{ $unwind: "$user" }
])Explanation
`$lookup` is the MongoDB pipeline equivalent of a join.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Core stages
Run multiple result sets with $facet
Produce multiple related aggregations in one pipeline.
Count pipeline output
Return a final count after filters and transforms.