【发布时间】:2018-06-05 00:56:56
【问题描述】:
假设我有以下文件
{
name: "Johnny Doe",
age: "55",
organizations: [
{name: "Org A",
members: 22
},
{name: "Org B",
members: 25
}]
}
假设我有另一个架构的虚拟设置
SomeSchema.virtual('organizations'){
ref:"Person", //the collection to reference
localField:"organization_name", //the field in this Schema
foreignField: [???] //I want to access Person.organizations[].name
}
如何在 localField/foreignField 中指定我想要的字段?我已经尝试过像 MongoDB 中一样的“organizations.$.name”,但它不起作用,它返回一个空数组。
【问题讨论】: