嵌套虚拟填充猫鼬

问题描述

我正在使用 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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...