mongodb join by _id
У меня есть такие коллекции:
hotels:
_id: ObjectId("5edabde015563b1ed0058862")
address: Object
city: "5ee381b36da22c44405003cb"
street: "Avenue de la Lanterne 50"
cities:
_id: ObjectId("5ee381b36da22c44405003cb")
label: Barselona
Как можно в отеле по city ID получить city label?
Делаю как-то так (ниже), не понимаю почему не получается:
{
"$lookup": {
"from": "cities",
"localField": "address['city']",
"foreignField": "_id",
"as": "role"
}
}
Монгус схемы:
const hotelSchema = mongoose.Schema({
address: {
address: {
city: { type: mongoose.Schema.ObjectId, trim: true },
street: { type: String, trim: true },
}
}
})
const citySchema = mongoose.Schema({
label: {
type: String,
trim: true
}
})