如何从猫鼬的嵌套对象中填充数据

我的架构如下:

 const commentSchema = new Schema({
  name: String,surname: String,email: String,positions: [
    { detail: [{
  type: Schema.Types.ObjectId,ref: 'Position'
}],progress: { type: String },// keep track of the status
comment: { type: String } // keep track of internal notes
}],});

字段详细信息包含mongo ID数组。

我正在尝试以下代码,但未获取填充数据:

const requirementsData = await Requirement.find({})
  .populate({
    path: "positions.detail",model: Position,})
  .exec(function(err,docs) {
           if(err){
               console.log("err====",err)
           }else{
               res.render('candidates/show',{candidate: docs})
           }
       });
no1xzb 回答:如何从猫鼬的嵌套对象中填充数据

如果我了解您的问题,您可以这样做

.populate({
path:'position',populate:{path:'details'}
})
本文链接:https://www.f2er.com/3131890.html

大家都在问