Nested Populate

17 views
Skip to first unread message

Merhawie Woldezion

unread,
Jul 27, 2013, 7:49:33 PM7/27/13
to mongoo...@googlegroups.com
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);

I don't understand why this isn't working, I feel that I am following: https://github.com/LearnBoost/mongoose/wiki/3.6-Release-Notes#added-modelpopulatedocs-opts-cb

Please, an advice would be helpfu, thank you.
Reply all
Reply to author
Forward
0 new messages