README
mongoose-power-populate
"Join" mongoose documents. Recursively populate document references in either direction.
DEPRECATED: Use Mongoose 4+ and mongoose-populate-virtuals instead.
Usage
Wrap mongoose to provide an improved populate()
method:
var mongoose = require('mongoose');
var populatePlugin = require('mongoose-power-populate')(mongoose);
Populate paths with predefined options:
Book.find().populate('author reviews').exec(...);
Specify options for population paths on the model:
BookSchema.plugin(populatePlugin, {
author: {
ref: 'User',
foreignKey: '_id',
localKey: 'authorId',
select: 'name',
lean: true,
singular: true
}
});
Populate nested paths:
User
.find(...)
.populate({
'posts': { ... },
'posts.comments': { ... }
})
.exec(...);
Override options at query time:
Book
.find()
.populate({
author: {
select: 'name isbn'
}
})
.exec(...);
Populate existing documents:
Book.populate(docs, 'author', callback);
Options
ref
Name of the mongoose model.foreignKey
Key on the model of the populated subdocuments.localKey
Key on the model being populated.singular
Whether to return a single result or an array of results.lean
Whether to populate with models or plain objects.query
Specify thefind()
query used to fetch related documented.select
Passed to mongoose's.select()
.