Ada banyak cara, salah satunya adalah menggunakan $lookup
seperti yang sudah Anda coba
db.place.aggregate([
{ "$match": { "place": "Room 5" } },
{ $unwind: "$type_place_objects" },
{
"$lookup": {
"from": "type_place",
"let": { tpo: "$type_place_objects._id" },
"pipeline": [
{ $unwind: "$objects" },
{
$match: {
$expr: {
$eq: [ "$objects._id", "$$tpo" ]
}
}
}
],
"as": "join"
}
},
{
$addFields: {
"join": { "$arrayElemAt": [ "$join", 0]
}
}
},
{
$addFields: { "type_place_objects.name": "$join.objects.name" }
},
{
$group: {
_id: "$_id",
place: { $first: "$place" },
type_place_objects: { "$addToSet": "$type_place_objects" }
}
}
])
Bekerja Taman bermain Mongo