I have a schema with references for population inside a sub-document.
var schema = new mongoose.Schema({
references: {
images: [{ref: 'Page', type: mongoose.Schema.Types.ObjectId}],
files: [{ref: 'Page', type: mongoose.Schema.Types.ObjectId}]
}
});
And then create a model for it, matching the name of the references (pages => pages).
var Page = mongoose.model('Page', schema);
I want to retrieve a page by its identifier and retrieve all references.
Page.findById(id)
.populate('references.images') // Err.. two populations..
.populate('references.files') // Err.. two populations..
.exec(function(err, page) {
// ... snip ...
});
Now I am doing multiple populations. How can I ensure that a single population loads the batch of arrays?
Since 3.6 pre-release it is possible to do:
Page.findById(id)
.populate('references.images references.files')
.exec(function(err, page) {
// ... snip ...
});