mongoose-paginate-v2
Advanced tools
Comparing version 1.3.8 to 1.3.9
@@ -58,3 +58,4 @@ "use strict"; | ||
options: {}, | ||
pagination: true | ||
pagination: true, | ||
forceCountFn: false | ||
}; | ||
@@ -74,3 +75,4 @@ | ||
sort = _options.sort, | ||
pagination = _options.pagination; | ||
pagination = _options.pagination, | ||
forceCountFn = _options.forceCountFn; | ||
@@ -111,4 +113,10 @@ var customLabels = _objectSpread({}, defaultOptions.customLabels, {}, options.customLabels); | ||
var countPromise = this.countDocuments(query).exec(); | ||
var countPromise; | ||
if (forceCountFn === true) { | ||
countPromise = this.count(query).exec(); | ||
} else { | ||
countPromise = this.countDocuments(query).exec(); | ||
} | ||
if (limit) { | ||
@@ -188,3 +196,3 @@ var mQuery = this.find(query, projection, findOptions); | ||
meta[labelPrevPage] = page - 1; | ||
} else if (page == 1 && offset && offset !== 0) { | ||
} else if (page == 1 && typeof offset !== 'undefined' && offset !== 0) { | ||
meta[labelHasPrevPage] = true; | ||
@@ -191,0 +199,0 @@ meta[labelPrevPage] = 1; |
{ | ||
"name": "mongoose-paginate-v2", | ||
"version": "1.3.8", | ||
"version": "1.3.9", | ||
"description": "A cursor based custom pagination library for Mongoose with customizable labels.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -61,2 +61,3 @@ ![Banner](static/banner.jpg) | ||
- `[pagination]` {Boolean} - If `pagination` is set to false, it will return all docs without adding limit condition. (Default: True) | ||
- `[forceCountFn]` {Boolean} - Set this to true, if you need to support $geo queries. | ||
- `[read]` {Object} - Determines the MongoDB nodes from which to read. Below are the available options. | ||
@@ -288,3 +289,3 @@ - `[pref]`: One of the listed preference options or aliases. | ||
## Note | ||
There are few operators that this plugin does not support, below are the list and suggested replacements, | ||
There are few operators that this plugin does not support natively, below are the list and suggested replacements, | ||
@@ -295,4 +296,21 @@ * $where: $expr | ||
But we have added another option. So if you need to use $near and $nearSphere please set `forceCountFn` as true and try running the query. | ||
```js | ||
const options = { | ||
lean: true, | ||
limit: 10, | ||
page: 1, | ||
forceCountFn: true | ||
}; | ||
Model.paginate({}, options, function(err, result) { | ||
// Result | ||
}); | ||
``` | ||
## License | ||
[MIT](LICENSE) |
@@ -43,3 +43,4 @@ /** | ||
options: {}, | ||
pagination: true | ||
pagination: true, | ||
forceCountFn: false | ||
}; | ||
@@ -64,3 +65,4 @@ | ||
sort, | ||
pagination | ||
pagination, | ||
forceCountFn | ||
} = options; | ||
@@ -109,4 +111,10 @@ | ||
const countPromise = this.countDocuments(query).exec(); | ||
let countPromise; | ||
if (forceCountFn === true) { | ||
countPromise = this.count(query).exec(); | ||
} else { | ||
countPromise = this.countDocuments(query).exec(); | ||
} | ||
if (limit) { | ||
@@ -191,3 +199,3 @@ const mQuery = this.find(query, projection, findOptions); | ||
meta[labelPrevPage] = (page - 1); | ||
} else if (page == 1 && offset && offset !== 0) { | ||
} else if (page == 1 && typeof offset !== 'undefined' && offset !== 0) { | ||
meta[labelHasPrevPage] = true; | ||
@@ -194,0 +202,0 @@ meta[labelPrevPage] = 1; |
@@ -131,3 +131,2 @@ 'use strict'; | ||
return Book.paginate(query, options).then(result => { | ||
expect(result.docs).to.have.length(10); | ||
@@ -394,7 +393,5 @@ expect(result.totalDocs).to.equal(100); | ||
loc: { | ||
$geoWithin: { | ||
$center: [ | ||
[-10, 20], 999 | ||
] | ||
} | ||
$nearSphere: | ||
[ 50, 50 ] | ||
} | ||
@@ -419,2 +416,3 @@ }; | ||
}, | ||
forceCountFn: true, | ||
customLabels: myCustomLabels | ||
@@ -421,0 +419,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
281110
819
314