mongoose-load-list
Easy queries with mongoose. Provides two methods .load()
and .list()
to query collections. Because chaining a lot of methods everywhere is not efficient.
Installation
$ npm install mongoose-load-list
API
var defaults = ;var Post = ... ;Post;
Make sure any statics you write in your model is done via function call and not with assignment. When the statics are assigned, the .load and .list will be overridden.
Post
Options
options.criteria
- default criteriaoptions.sort
- default sortoptions.select
- default fieldsoptions.limit
- default limitoptions.populate
- default populated fieldsoptions.lean
- default is false
The default options are always applied on all the .load
and .list
methods. It can be overridden like below.
Example:
var Post = mongoose;var options = select: 'title body created_at user' criteria: _id: thisparamsid // more criterias sort: title: -1 limit: 10 skip: 10 // useful for pagination populate: path: 'users' select: 'name email' lean: true // only for list methods Post;
.load(options)
does a .findOne
on Post collection with all the options passed
Post;
.list(options)
does a .find
on Post collection with all the options passed
Post;
License
MIT