$lookup
rejoindre la collection de la ville
$lookup
rejoindre la collection de pays
$project
pour afficher les champs obligatoires, obtenez le premier élément de city
et country
en utilisant $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" }
}
}
])
Aire de jeux