1.3.4 • Published 10 years ago
mongoose-power-populate v1.3.4
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
refName of the mongoose model.foreignKeyKey on the model of the populated subdocuments.localKeyKey on the model being populated.singularWhether to return a single result or an array of results.leanWhether to populate with models or plain objects.querySpecify thefind()query used to fetch related documented.selectPassed to mongoose's.select().