I have Category
model:
Category:
...
articles: [{type:ObjectId, ref:\'Article\'}]
Article model contains ref to
If you want select multi populate inside populate, you should try this way:
I have Booking schema:
let Booking = new Schema({
..., // others field of collection
experience: { type: Schema.Types.ObjectId, ref: 'Experience' },
...},{
collection: 'booking'
});
and Experience schema:
let Experience = new Schema({
...,
experienceType: {type: Schema.Types.ObjectId, ref: 'ExperienceType'},
location: {type: Schema.Types.ObjectId, ref: 'Location'},
...} // others field of collection
,{
collection: 'experience'
});
get ExperienceType and Location of Experience when you find Booking:
Booking.findOne({_id: req.params.id})
.populate({path: 'experience',
populate: [{path: 'experienceType', select: 'name'}, {path: 'location', select: 'name'}],
})
.exec((err, booking) => {
if(err){
console.log(err);
}
else {
res.json(booking);
}
});