Suppose we have a schema A which looks like:
{ b: { type: Schema.Types.ObjectId, ref: 'B' }
,
a type B which looks like:
{ c: { type: Schema.Types.ObjectId, ref: 'C' }
,
and a type C which looks like:
{ name: String }
.
Is there any way to use MongooseJS' populate utility to get at documents through multiple refs? In the example, we could find A's b by doing
A.findOne({ id: someId })
.populate('b')
...
but could we get at b's c through A?
Not currently. Some support for this is coming soon.
I think things changed since two years. What about the following Model.populate() use:
A.findOne({id: someId})
.populate('b')
.exec()
.then(function(data) {
// returns a promise about populating a.b.c:
return C.populate(data, {path: 'b.c'});
});
Details can be found in the 3.6' Release Notes: https://github.com/LearnBoost/mongoose/wiki/3.6-Release-Notes#added-modelpopulatedocs-opts-cb