我有Adresses模特:
{
user1: ObjectId(),
user2: ObjectId()
}
每个用户字段都是对用户模型的引用。 是否可以执行一次传播数据的查找?
答案 0 :(得分:0)
您可以按如下方式放置多个参考:
collection.aggregate([
{
$lookup: {
from: "whereyouwant",
localField: "localfield",
foreignField: "foreignfield",
as: "name1"
}
},
{
$lookup: {
from: "whereyouwant2",
localField: "localfield2",
foreignField: "foreignfield2",
as: "name2"
}
},... rest of code