2.0.0 • Published 3 months ago

mongoose-query-paginate v2.0.0

Weekly downloads
331
License
MIT
Repository
github
Last release
3 months ago

mongoose-query-paginate

Mongoose Query paginate.

Installation

$ npm install mongoose-query-paginate

Example

require('mongoose-query-paginate');
var options = {
  perPage: 10,
  delta  : 3,
  page   : req.query.p
};
var query = MyModel.find({deleted: false}).sort('name', 1);
query.paginate(options, function(err, res) {
  console.log(res); // => res = {
    //  options: options,               // paginate options
    //  results: [Document, ...],       // mongoose results
    //  current: 5,                     // current page number
    //  last: 12,                       // last page number
    //  prev: 4,                        // prev number or null
    //  next: 6,                        // next number or null
    //  pages: [ 2, 3, 4, 5, 6, 7, 8 ], // page numbers
    //  count: 125                      // document count
  //};
});

Migration from v1.x to v2

Instead of using callbacks, the paginate method now returns a promise.

So it becomes:

const pager = await query.paginate(options);

License

The MIT License

2.0.0

3 months ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

12 years ago

1.0.0

12 years ago

0.0.4

13 years ago

0.0.3

13 years ago

0.0.2

13 years ago

0.0.1

13 years ago