$lookup
deltage i byindsamling$lookup
deltage i landeindsamling$project
for at vise obligatoriske felter, hent det første element fracity
ogcountry
ved hjælp af$first
db.travel_reservation.aggregate([
{
$lookup: {
from: "city",
localField: "city_id",
foreignField: "_id",
as: "city"
}
},
{
$lookup: {
from: "country",
localField: "city.country_id",
foreignField: "_id",
as: "country"
}
},
{
$project: {
name_person: 1,
city: { $first: "$city" },
country: { $first: "$country" }
}
}
])