如何解决嵌套虚拟填充猫鼬
我正在使用 mongoDB,需要进行复杂的虚拟填充。已为其他 virtual.populate 完成此操作:
const itemSchema = new mongoose.Schema(
{
localField: { type: Object,required: true },},)
itemSchema.virtual('populated',{
ref: 'Foreign',localField: 'parameter1',foreignField: 'parameter1',})
foreignField 参数是嵌套在对象内的对象数组,如果任何字符串都等于 localField 中的两个值,则应填充该数组。
所以,有这个本地字段:
localField = {
parameter1: 'BBB',parameter2: 'bbb',}
外国人应该被填充,但如果没有这个:
localField = {
parameter1: 'HHH',parameter2: 'hhh',}
给定这个foreignField:
coonst foreignField = {
items: [
{
parameter1: 'AAA',parameter2: 'aaa',{
parameter1: 'BBB',}
]
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。