I have an Element model
var ElementSchema = new Schema({
...
sub : [{type: Schema.Types.ObjectId, ref:'Element'}]
...
});
var Element = mongoose.model('Element', ElementSchema);
I am trying to do a nested populate because I have many levels of nested documents
{ __v: 6,
_id: ***6000001,
sub:
[ { __v: 4,
_id: ***a000001,
sub: [Object]
...
} ]
}
When I do
Element.findOne({_id:
req.params.id}).exec(function (err, docs) {
Element.populate(docs, {path: "sub"}, function(err, docs){
Element.populate(docs, {path: "sub.sub"}, function(err, docs){
console.log(utils.inspect(docs, false, null));
});
});
});
The result is this: foundschema = schema.path(trypath);
Please, an advice would be helpfu, thank you.