如何填充参考文档中子文档,这是我的架构:如何填充的子文档的参考(猫鼬)
var person = mongoose.Schema({
name: { type: [String], index: true },
career: [{
position: { type: mongoose.Schema.Types.ObjectId, ref: 'Orgchart' }
}]
};
var orgchart = mongoose.Schema({
name: { type: [String], index: true },
};
我用这部分尝试:
person.find({ _id: "12345" }).populate('orgchart').exec(function(err, data){
res.send(data);
});
我得到了错误Cannot read property 'name' of undefined
当我打电话给玉模板
item.career._orgchart.name