0

I am having schema like below:

 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
}],
});

Field detail contains array of mongo ids.

I am trying with below code but not getting the populated data:

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})
           }
       });

1 Answers1

0

if I understand your problem you can do this

.populate({
path:'position',
populate:{path:'details'}
})
M.Amer
  • 658
  • 6
  • 13