How to populate ref document in Sub Document, this my schema:
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 },
};
I tried with this part:
person.find({ _id: "12345" }).populate('orgchart').exec(function(err, data){
res.send(data);
});
I got error Cannot read property 'name' of undefined
when i call on jade template with
item.career._orgchart.name