如何在猫鼬的嵌套数组中填充对象字段

时间:2019-11-08 15:15:04

标签: mongodb mongoose

const personScheema = new Scheema({
info: {
        firstName: String,
        lastName: String
}
record: {
   tests: [
        [{
            name: String,
            report: {
            comment: String,
            attachments: [],
            meta: {
                    addedBy: {
                        type: Scheema.Types.ObjectId,
                        ref: 'Person'
                    },
                    selected: Boolean,
                    dateAdded: Date
                }
            }
        }]
      ]
   }
 })

上面是我想要在报告对象中填充“ add byBy”字段的示意图,但是当我尝试以下代码时,我一直得到空结果:

  await Person.findById(req.params.id).populate({
  path:'record.tests',
  populate: {path:'report.meta.addedBy', Model: 'Person', select:'info'}
})
.exec()

0 个答案:

没有答案