MongoDB — Reporting Project, Leaderboards & $lookup Joins
Join collections using $lookup left outer joins, sort results, and paginate aggregation results.
1Left Outer Join with $lookup
$lookup Join Example
db.orders.aggregate([
{
$lookup: {
from: "users", // Foreign collection
localField: "userId", // Local key
foreignField: "_id", // Foreign key
as: "userDetails" // Output array name
}
},
{ $unwind: "$userDetails" }
]);