我的架构如下:
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})
}
});
答案 0 :(得分:0)
如果我了解您的问题,您可以这样做
.populate({
path:'position',
populate:{path:'details'}
})