Gathering detailed insights and metrics for bos-mongoose-paginate
Gathering detailed insights and metrics for bos-mongoose-paginate
Gathering detailed insights and metrics for bos-mongoose-paginate
Gathering detailed insights and metrics for bos-mongoose-paginate
npm install bos-mongoose-paginate
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Commits
2 Watching
1 Branches
1 Contributors
Updated on 13 Oct 2021
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
77.8%
16
Compared to previous week
Last month
137.5%
57
Compared to previous month
Last year
-8%
518
Compared to previous year
Pagination plugin for Mongoose (Support mongo >= 4.0)
1npm install bos-mongoose-paginate
Add plugin to a schema and then use model paginate
method:
1var mongoose = require('mongoose'); 2var mongoosePaginate = require('bos-mongoose-paginate'); 3 4var schema = new mongoose.Schema({ /* schema definition */ }); 5schema.plugin(mongoosePaginate); 6 7var Model = mongoose.model('Model', schema); // Model.paginate()
Parameters
[query]
{Object} - Query criteria. Documentation[options]
{Object}
[select]
{Object | String} - Fields to return (by default returns all fields). Documentation[sort]
{Object | String} - Sort order. Documentation[populate]
{Array | Object | String} - Paths which should be populated with other documents. Documentation[lean=false]
{Boolean} - Should return plain javascript objects instead of Mongoose documents? Documentation[leanWithId=true]
{Boolean} - If lean
and leanWithId
are true
, adds id
field with string representation of _id
to every document[offset=0]
{Number} - Use offset
or page
to set skip position[page=1]
{Number}[limit=10]
{Number}[maxTimeMS]
{Number} - Use maxTimeMS[setOptions={}]
{Object} - Use setOptions
to use setOptions method[callback(err, result)]
- If specified the callback is called once pagination results are retrieved or when an error has occurredReturn value
Promise fulfilled with object having properties:
docs
{Array} - Array of documentstotal
{Number} - Total number of documents in collection that match a querylimit
{Number} - Limit that was used[page]
{Number} - Only if specified or default page
/offset
values were used[pages]
{Number} - Only if page
specified or default page
/offset
values were used[offset]
{Number} - Only if specified or default page
/offset
values were used1Model.paginate({}, { page: 3, limit: 10 }, function(err, result) { 2 // result.docs 3 // result.total 4 // result.limit - 10 5 // result.page - 3 6 // result.pages 7});
Or you can do the same with offset
and limit
:
1Model.paginate({}, { offset: 20, limit: 10 }, function(err, result) { 2 // result.docs 3 // result.total 4 // result.limit - 10 5 // result.offset - 20 6});
With promise:
1Model.paginate({}, { offset: 20, limit: 10 }).then(function(result) { 2 // ... 3});
1var query = {}; 2var options = { 3 select: 'title date author', 4 sort: { date: -1 }, 5 populate: 'author', 6 lean: true, 7 offset: 20, 8 limit: 10 9}; 10 11Book.paginate(query, options).then(function(result) { 12 // ... 13});
You can use limit=0
to get only metadata:
1Model.paginate({}, { offset: 100, limit: 0 }).then(function(result) { 2 // result.docs - empty array 3 // result.total 4 // result.limit - 0 5 // result.offset - 100 6});
config.js:
1var mongoosePaginate = require('bos-mongoose-paginate'); 2 3mongoosePaginate.paginate.options = { 4 lean: true, 5 limit: 20 6};
controller.js:
1Model.paginate().then(function(result) { 2 // result.docs - array of plain javascript objects 3 // result.limit - 20 4});
1npm install 2npm test
No vulnerabilities found.
No security vulnerabilities found.