I have challenge here where I am trying to populate a subdocument from another subdocument which is in same collection. Is this possible?Below is example schemas I have
var chapter = new Schema({
title:String,
startPage:Number,
endPage:Number
});
var keyPoint = new Schema({
text:String,
mentionInChapter:[{
type: Schema.ObjectId,
ref: 'chapter'}]
});
var Book = new Schema({
title:String,
author:String,
chapters:[chapter],
keyPoints:[keypoint]
});
I tried below and it did not populate the chapterId in keyPoints array.
Book.findById(id).populate('chapter').exec(function(err,doc){ if(!err) console.log(doc); });
Is there a way to achieve this so that Book document I retrieve has all the details populated?