猫鼬添加到父数组

时间:2021-03-08 14:26:32

标签: mongodb mongoose mongoose-populate

我有以下猫鼬模型 -

file:
{
  name: string,
  links: [{
     views: [{
         type: mongoose.Schema.Types.ObjectId,
         ref: 'view',
     }]
  }]
}

view:
{
  link: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'file.links',
    index: true,
  }
}

当我创建视图时,它会在 view 文档中设置正确的链接,但是,视图 ID 不会添加到文件 document 中的链接数组中。

是否可以自动完成?另外,在查询 views 文档时如何填充 file

0 个答案:

没有答案
相关问题