Mongoose plugin to enable population of nested models at any level of depth. Support Mongoose 3.8.x and later. Refer to changelog for breaking changes. (https://www.npmjs.com/package/mongoose-deep-populate)
Usage
Sample usages are based on the following schemas:
var UserSchema = {} var CommentSchema = user : type: Number ref: 'User' var PostSchema = user : type: Number ref: 'User' comments: type: Number ref: 'Comment' likes : user: type: Number ref: 'User' approved: status: Boolean user: type: Number ref: 'User'
Register plugin
// CHANGE from 1.x: need to pass in mongoose instancevar deepPopulate = mongoose;PostSchema;
Perform population
On Post
model:
// Use callbackPost; // Use promisePost;
On an instance of Post
:
// Use callbackpost; // Use promisepost;
On Query
(returns the same query object to chain):
Post;Post;Post;
Populate multiple paths
post;
Test
The test suite will drop the database each run, so only run it against a test database. To run tests, execute this command where --db
is the connection string.
gulp test --db mongodb://127.0.0.1/mongoose_deep_populate_test_db
Changelog
v0.0.1
- Initial release
License
MIT