Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-paginate-v2

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-paginate-v2 - npm Package Compare versions

Comparing version 1.3.11 to 1.3.12

.eslintrc.js

20

CODE_OF_CONDUCT.md

@@ -11,15 +11,15 @@ # Contributor Covenant Code of Conduct

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
- The use of sexualized language or imagery and unwelcome sexual attention or advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a professional setting

@@ -26,0 +26,0 @@ ## Our Responsibilities

@@ -37,2 +37,3 @@ "use strict";

* @param {Boolean} [options.useEstimatedCount=true] - Enable estimatedDocumentCount for larger datasets. As the name says, the count may not abe accurate.
* @param {Function} [options.useCustomCountFn=false] - use custom function for count datasets.
* @param {Object} [options.read={}] - Determines the MongoDB nodes from which to read.

@@ -66,2 +67,3 @@ * @param {Function} [callback]

useEstimatedCount: false,
useCustomCountFn: false,
forceCountFn: false

@@ -84,2 +86,3 @@ };

useEstimatedCount = _options.useEstimatedCount,
useCustomCountFn = _options.useCustomCountFn,
forceCountFn = _options.forceCountFn;

@@ -109,6 +112,6 @@

if (options.hasOwnProperty('offset')) {
if (Object.prototype.hasOwnProperty.call(options, 'offset')) {
offset = parseInt(options.offset, 10);
skip = offset;
} else if (options.hasOwnProperty('page')) {
} else if (Object.prototype.hasOwnProperty.call(options, 'page')) {
page = parseInt(options.page, 10);

@@ -125,3 +128,3 @@ skip = (page - 1) * limit;

if (forceCountFn === true) {
// Deprecated since starting from MongoDB Node.JS driver v3.1
// Deprecated since starting from MongoDB Node.JS driver v3.1
countPromise = this.count(query).exec();

@@ -131,2 +134,4 @@ } else {

countPromise = this.estimatedDocumentCount().exec();
} else if (typeof useCustomCountFn === 'function') {
countPromise = useCustomCountFn();
} else {

@@ -133,0 +138,0 @@ countPromise = this.countDocuments(query).exec();

{
"name": "mongoose-paginate-v2",
"version": "1.3.11",
"version": "1.3.12",
"description": "A cursor based custom pagination library for Mongoose with customizable labels.",

@@ -10,4 +10,20 @@ "main": "dist/index.js",

"build": "babel src -d dist",
"lint": "./node_modules/.bin/eslint \"tests\" \"src\" \".eslintrc.js\" --fix",
"prettier": "./node_modules/.bin/prettier --write \"{src,tests}/**/*.js\" \"*.md\"",
"prepublish": "npm run test"
},
"husky": {
"hooks": {
"pre-commit": "./node_modules/.bin/lint-staged"
}
},
"lint-staged": {
"*.js": [
"./node_modules/.bin/eslint --fix",
"./node_modules/.bin/prettier --write"
],
"*.md": [
"./node_modules/.bin/prettier --write"
]
},
"repository": {

@@ -62,5 +78,11 @@ "type": "git",

"@babel/preset-env": "^7.12.1",
"babel-eslint": "^10.1.0",
"chai": "^4.2.0",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"husky": "^4.3.0",
"lint-staged": "^10.5.1",
"mocha": "^8.2.1",
"mongoose": "^5.10.12"
"mongoose": "^5.10.12",
"prettier": "^2.1.2"
},

@@ -67,0 +89,0 @@ "engines": {

![Banner](static/banner.jpg)
# mongoose-paginate-v2
[![npm version](https://img.shields.io/npm/v/mongoose-paginate-v2.svg)](https://www.npmjs.com/package/mongoose-paginate-v2)

@@ -19,2 +20,3 @@ [![Build Status](https://travis-ci.com/aravindnc/mongoose-paginate-v2.svg?branch=master)](https://travis-ci.com/aravindnc/mongoose-paginate-v2)

## Why This Plugin
mongoose-paginate-v2 is a cursor based pagination library having a page wrapper. The plugin can be used as both page as well as cusror based pagination. The main usage of the plugin is you can alter the return value keys directly in the query itself so that you don't need any extra code for transformation.

@@ -35,3 +37,3 @@

```js
const mongoose = require('mongoose');
const mongoose = require('mongoose');
const mongoosePaginate = require('mongoose-paginate-v2');

@@ -45,5 +47,5 @@

const myModel = mongoose.model('SampleModel', mySchema);
const myModel = mongoose.model('SampleModel', mySchema);
myModel.paginate().then({}) // Usage
myModel.paginate().then({}); // Usage
```

@@ -57,4 +59,4 @@

* `[query]` {Object} - Query criteria. [Documentation](https://docs.mongodb.org/manual/tutorial/query-documents)
* `[options]` {Object}
- `[query]` {Object} - Query criteria. [Documentation](https://docs.mongodb.org/manual/tutorial/query-documents)
- `[options]` {Object}
- `[select]` {Object | String} - Fields to return (by default returns all fields). [Documentation](http://mongoosejs.com/docs/api.html#query_Query-select)

@@ -65,3 +67,3 @@ - `[collation]` {Object} - Specify the collation [Documentation](https://docs.mongodb.com/manual/reference/collation/)

- `[projection]` {String | Object} - Get/set the query projection. [Documentation](https://mongoosejs.com/docs/api/query.html#query_Query-projection)
- `[lean=false]` {Boolean} - Should return plain javascript objects instead of Mongoose documents? [Documentation](http://mongoosejs.com/docs/api.html#query_Query-lean)
- `[lean=false]` {Boolean} - Should return plain javascript objects instead of Mongoose documents? [Documentation](http://mongoosejs.com/docs/api.html#query_Query-lean)
- `[leanWithId=true]` {Boolean} - If `lean` and `leanWithId` are `true`, adds `id` field with string representation of `_id` to every document

@@ -74,3 +76,4 @@ - `[offset=0]` {Number} - Use `offset` or `page` to set skip position

- `[useEstimatedCount]` - Enable [estimatedDocumentCount](https://docs.mongodb.com/manual/reference/method/db.collection.estimatedDocumentCount/) for larger datasets. Does not count based on given query, so the count will match entire collection size. (Default: False)
- `[forceCountFn]` {Boolean} - Set this to true, if you need to support $geo queries. (Default: False)
- `[useCustomCountFn]` - Enable custom function for count datasets. (Default: False)
- `[forceCountFn]` {Boolean} - Set this to true, if you need to support \$geo queries. (Default: False)
- `[read]` {Object} - Determines the MongoDB nodes from which to read. Below are the available options.

@@ -80,3 +83,3 @@ - `[pref]`: One of the listed preference options or aliases.

- `[options]` {Object} - Options passed to Mongoose's `find()` function. [Documentation](https://mongoosejs.com/docs/api.html#query_Query-setOptions)
* `[callback(err, result)]` - If specified, the callback is called once pagination results are retrieved or when an error has occurred
- `[callback(err, result)]` - If specified, the callback is called once pagination results are retrieved or when an error has occurred

@@ -87,14 +90,14 @@ **Return value**

* `docs` {Array} - Array of documents
* `totalDocs` {Number} - Total number of documents in collection that match a query
* `limit` {Number} - Limit that was used
* `hasPrevPage` {Bool} - Availability of prev page.
* `hasNextPage` {Bool} - Availability of next page.
* `page` {Number} - Current page number
* `totalPages` {Number} - Total number of pages.
* `offset` {Number} - Only if specified or default `page`/`offset` values were used
* `prevPage` {Number} - Previous page number if available or NULL
* `nextPage` {Number} - Next page number if available or NULL
* `pagingCounter` {Number} - The starting sl. number of first document.
* `meta` {Object} - Object of pagination meta data (Default false).
- `docs` {Array} - Array of documents
- `totalDocs` {Number} - Total number of documents in collection that match a query
- `limit` {Number} - Limit that was used
- `hasPrevPage` {Bool} - Availability of prev page.
- `hasNextPage` {Bool} - Availability of next page.
- `page` {Number} - Current page number
- `totalPages` {Number} - Total number of pages.
- `offset` {Number} - Only if specified or default `page`/`offset` values were used
- `prevPage` {Number} - Previous page number if available or NULL
- `nextPage` {Number} - Next page number if available or NULL
- `pagingCounter` {Number} - The starting sl. number of first document.
- `meta` {Object} - Object of pagination meta data (Default false).

@@ -112,7 +115,7 @@ Please note that the above properties can be renamed by setting customLabels attribute.

collation: {
locale: 'en'
}
locale: 'en',
},
};
Model.paginate({}, options, function(err, result) {
Model.paginate({}, options, function (err, result) {
// result.docs

@@ -135,13 +138,13 @@ // result.totalDocs = 100

* totalDocs
* docs
* limit
* page
* nextPage
* prevPage
* hasNextPage
* hasPrevPage
* totalPages
* pagingCounter
* meta
- totalDocs
- docs
- limit
- page
- nextPage
- prevPage
- hasNextPage
- hasPrevPage
- totalPages
- pagingCounter
- meta

@@ -162,3 +165,3 @@ You should pass the names of the properties you wish to changes using `customLabels` object in options.

pagingCounter: 'slNo',
meta: 'paginator'
meta: 'paginator',
};

@@ -169,6 +172,6 @@

limit: 10,
customLabels: myCustomLabels
customLabels: myCustomLabels,
};
Model.paginate({}, options, function(err, result) {
Model.paginate({}, options, function (err, result) {
// result.itemsList [here docs become itemsList]

@@ -192,3 +195,3 @@ // result.paginator.itemCount = 100 [here totalDocs becomes itemCount]

```javascript
Model.paginate({}, { offset: 30, limit: 10 }, function(err, result) {
Model.paginate({}, { offset: 30, limit: 10 }, function (err, result) {
// result.docs

@@ -204,3 +207,3 @@ // result.totalPages

```js
Model.paginate({}, { offset: 30, limit: 10 }).then(function(result) {
Model.paginate({}, { offset: 30, limit: 10 }).then(function (result) {
// ...

@@ -213,13 +216,13 @@ });

```javascript
var query = {};
var query = {};
var options = {
select: 'title date author',
sort: { date: -1 },
select: 'title date author',
sort: { date: -1 },
populate: 'author',
lean: true,
offset: 20,
limit: 10
lean: true,
offset: 20,
limit: 10,
};
Book.paginate(query, options).then(function(result) {
Book.paginate(query, options).then(function (result) {
// ...

@@ -234,3 +237,3 @@ });

```javascript
Model.paginate({}, { limit: 0 }).then(function(result) {
Model.paginate({}, { limit: 0 }).then(function (result) {
// result.docs - empty array

@@ -250,4 +253,4 @@ // result.totalDocs

mongoosePaginate.paginate.options = {
lean: true,
limit: 20
lean: true,
limit: 20,
};

@@ -259,3 +262,3 @@ ```

```javascript
Model.paginate().then(function(result) {
Model.paginate().then(function (result) {
// result.docs - array of plain javascript objects

@@ -267,2 +270,3 @@ // result.limit - 20

#### Fetch all docs without pagination.
If you need to fetch all the documents in the collection without applying a limit. Then set `pagination` as false,

@@ -272,6 +276,6 @@

const options = {
pagination: false
pagination: false,
};
Model.paginate({}, options, function(err, result) {
Model.paginate({}, options, function (err, result) {
// result.docs

@@ -290,3 +294,20 @@ // result.totalDocs = 100

#### Using custom count function
If you need to use your own custom count function, then set `useCustomCountFn` as your custom count function. Make sure the function is returning count as a **promise**.
```javascript
const options = {
useCustomCountFn: function () {
return Promise.resolve(100);
},
};
Model.paginate({}, options, function (err, result) {
// result.docs
});
```
#### Setting read preference.
Determines the MongoDB nodes from which to read.

@@ -301,10 +322,12 @@

pref: 'secondary',
tags: [{
region: 'South'
}]
}
tags: [
{
region: 'South',
},
],
},
};
Model.paginate({}, options, function(err, result) {
// Result
Model.paginate({}, options, function (err, result) {
// Result
});

@@ -314,2 +337,3 @@ ```

Below are some references to understand more about preferences,
- https://github.com/Automattic/mongoose/blob/master/lib/query.js#L1008

@@ -320,7 +344,8 @@ - https://docs.mongodb.com/manual/core/read-preference/

## Note
There are few operators that this plugin does not support natively, below are the list and suggested replacements,
* $where: $expr
* $near: $geoWithin with $center
* $nearSphere: $geoWithin with $centerSphere
- $where: $expr
- $near: $geoWithin with \$center
- $nearSphere: $geoWithin with \$centerSphere

@@ -334,17 +359,16 @@ 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.

page: 1,
forceCountFn: true
forceCountFn: true,
};
Model.paginate({}, options, function(err, result) {
// Result
Model.paginate({}, options, function (err, result) {
// Result
});
```
## Changelog
[v1.3.10] - 1/11/2020
- Added support for estimatedCountDocuments for larger datasets. Set useEstimatedCount=true
## Development
[v1.3.11] - 6/11/2020
- Fixes to estimateDocumentCount implementation.
- Package version updates to support Node v12.
- Ensure all tests pass before you commit by running `npm run test`
- There are pre-commit hooks that run to ensure the _files you've changed_ are formatted correctly.
- Optionally you can manually run `npm run lint && npm run prettier` to lint and format every relevant file
- If using VS Code, install eslint and prettier for easy editor integration.

@@ -351,0 +375,0 @@ ## License

@@ -17,2 +17,3 @@ /**

* @param {Boolean} [options.useEstimatedCount=true] - Enable estimatedDocumentCount for larger datasets. As the name says, the count may not abe accurate.
* @param {Function} [options.useCustomCountFn=false] - use custom function for count datasets.
* @param {Object} [options.read={}] - Determines the MongoDB nodes from which to read.

@@ -47,3 +48,4 @@ * @param {Function} [callback]

useEstimatedCount: false,
forceCountFn: false
useCustomCountFn: false,
forceCountFn: false,
};

@@ -55,3 +57,3 @@

...paginate.options,
...options
...options,
};

@@ -71,3 +73,4 @@ query = query || {};

useEstimatedCount,
forceCountFn
useCustomCountFn,
forceCountFn,
} = options;

@@ -77,6 +80,7 @@

...defaultOptions.customLabels,
...options.customLabels
...options.customLabels,
};
const limit = parseInt(options.limit, 10) > 0 ? parseInt(options.limit, 10) : 0;
const limit =
parseInt(options.limit, 10) > 0 ? parseInt(options.limit, 10) : 0;

@@ -105,6 +109,6 @@ const isCallbackSpecified = typeof callback === 'function';

if (options.hasOwnProperty('offset')) {
if (Object.prototype.hasOwnProperty.call(options, 'offset')) {
offset = parseInt(options.offset, 10);
skip = offset;
} else if (options.hasOwnProperty('page')) {
} else if (Object.prototype.hasOwnProperty.call(options, 'page')) {
page = parseInt(options.page, 10);

@@ -121,10 +125,12 @@ skip = (page - 1) * limit;

if (forceCountFn === true) {
// Deprecated since starting from MongoDB Node.JS driver v3.1
// Deprecated since starting from MongoDB Node.JS driver v3.1
countPromise = this.count(query).exec();
} else {
if (useEstimatedCount === true) {
countPromise = this.estimatedDocumentCount().exec()
} else {
countPromise = this.countDocuments(query).exec();
}
if (useEstimatedCount === true) {
countPromise = this.estimatedDocumentCount().exec();
} else if (typeof useCustomCountFn === 'function') {
countPromise = useCustomCountFn();
} else {
countPromise = this.countDocuments(query).exec();
}
}

@@ -166,5 +172,5 @@

docs.forEach((doc) => {
if(doc._id) {
doc.id = String(doc._id);
}
if (doc._id) {
doc.id = String(doc._id);
}
});

@@ -174,3 +180,2 @@ return docs;

}
}

@@ -180,6 +185,5 @@

.then((values) => {
const [count, docs] = values;
const meta = {
[labelTotal]: count
[labelTotal]: count,
};

@@ -194,3 +198,3 @@

const pages = (limit > 0) ? (Math.ceil(count / limit) || 1) : null;
const pages = limit > 0 ? Math.ceil(count / limit) || 1 : null;

@@ -201,3 +205,3 @@ // Setting default values

meta[labelPage] = page;
meta[labelPagingCounter] = ((page - 1) * limit) + 1;
meta[labelPagingCounter] = (page - 1) * limit + 1;

@@ -210,3 +214,2 @@ meta[labelHasPrevPage] = false;

if (pagination) {
meta[labelLimit] = limit;

@@ -218,3 +221,3 @@ meta[labelTotalPages] = pages;

meta[labelHasPrevPage] = true;
meta[labelPrevPage] = (page - 1);
meta[labelPrevPage] = page - 1;
} else if (page == 1 && typeof offset !== 'undefined' && offset !== 0) {

@@ -230,7 +233,6 @@ meta[labelHasPrevPage] = true;

meta[labelHasNextPage] = true;
meta[labelNextPage] = (page + 1);
meta[labelNextPage] = page + 1;
} else {
meta[labelNextPage] = null;
}
}

@@ -255,3 +257,3 @@

[labelDocs]: docs,
[labelMeta]: meta
[labelMeta]: meta,
};

@@ -261,8 +263,11 @@ } else {

[labelDocs]: docs,
...meta
...meta,
};
}
return isCallbackSpecified ? callback(null, result) : Promise.resolve(result);
}).catch((error) => {
return isCallbackSpecified
? callback(null, result)
: Promise.resolve(result);
})
.catch((error) => {
return isCallbackSpecified ? callback(error) : Promise.reject(error);

@@ -269,0 +274,0 @@ });

@@ -11,3 +11,3 @@ 'use strict';

let AuthorSchema = new mongoose.Schema({
name: String
name: String,
});

@@ -22,9 +22,9 @@ let Author = mongoose.model('Author', AuthorSchema);

type: mongoose.Schema.ObjectId,
ref: 'Author'
ref: 'Author',
},
loc: Object
loc: Object,
});
BookSchema.index({
loc: "2dsphere"
loc: '2dsphere',
});

@@ -37,8 +37,11 @@

describe('mongoose-paginate', function () {
before(function (done) {
mongoose.connect(MONGO_URI, {
useUnifiedTopology: true,
useNewUrlParser: true
}, done);
mongoose.connect(
MONGO_URI,
{
useUnifiedTopology: true,
useNewUrlParser: true,
},
done
);
});

@@ -51,7 +54,8 @@

before(function () {
let book, books = [];
let book,
books = [];
let date = new Date();
return Author.create({
name: 'Arthur Conan Doyle'
name: 'Arthur Conan Doyle',
}).then(function (author) {

@@ -61,3 +65,3 @@ for (let i = 1; i <= 100; i++) {

// price: Math.floor(Math.random() * (1000 - 50) ) + 50,
price: (i * 5) + i,
price: i * 5 + i,
title: 'Book #' + i,

@@ -67,4 +71,4 @@ date: new Date(date.getTime() + i),

loc: {
type: "Point",
coordinates: [-10.97, 20.77]
type: 'Point',
coordinates: [-10.97, 20.77],
},

@@ -77,11 +81,7 @@ });

});
});
afterEach(function () {
afterEach(function () {});
});
it('promise return test', function () {
let promise = Book.paginate();

@@ -102,4 +102,4 @@ expect(promise.then).to.be.an.instanceof(Function);

title: {
$in: [/Book/i]
}
$in: [/Book/i],
},
};

@@ -110,3 +110,3 @@

page: 5,
lean: true
lean: true,
};

@@ -127,4 +127,4 @@

});
it('first page with page and limit', function() {
it('first page with page and limit', function () {
var query = {

@@ -142,3 +142,3 @@ title: {

return Book.paginate(query, options).then(result => {
return Book.paginate(query, options).then((result) => {
expect(result.docs).to.have.length(10);

@@ -157,3 +157,3 @@ expect(result.totalDocs).to.equal(100);

it('last page with page and limit', function() {
it('last page with page and limit', function () {
var query = {

@@ -171,4 +171,4 @@ title: {

return Book.paginate(query, options).then(result => {
expect(result.docs).to.have.length(10);
return Book.paginate(query, options).then((result) => {
expect(result.docs).to.have.length(10);
expect(result.totalDocs).to.equal(100);

@@ -189,4 +189,4 @@ expect(result.limit).to.equal(10);

title: {
$in: [/Book/i]
}
$in: [/Book/i],
},
};

@@ -198,9 +198,8 @@

sort: {
_id: 1
_id: 1,
},
lean: true
lean: true,
};
return Book.paginate(query, options).then((result) => {
expect(result.docs).to.have.length(2);

@@ -218,8 +217,8 @@ expect(result.totalDocs).to.equal(100);

});
it('with offset and limit (not page) condition: offset > 0 < limit', function () {
var query = {
title: {
$in: [/Book/i]
}
$in: [/Book/i],
},
};

@@ -231,9 +230,8 @@

sort: {
_id: 1
_id: 1,
},
lean: true
lean: true,
};
return Book.paginate(query, options).then((result) => {
expect(result.docs).to.have.length(10);

@@ -255,4 +253,4 @@ expect(result.totalDocs).to.equal(100);

title: {
$in: [/Book #1/i]
}
$in: [/Book #1/i],
},
};

@@ -263,9 +261,9 @@

sort: {
_id: 1
_id: 1,
},
collation: {
locale: 'en',
strength: 2
strength: 2,
},
lean: true
lean: true,
};

@@ -319,4 +317,4 @@

title: {
$in: [/Book/i]
}
$in: [/Book/i],
},
};

@@ -331,3 +329,3 @@

sort: {
_id: 1
_id: 1,
},

@@ -338,8 +336,7 @@ limit: 10,

title: 1,
price: 1
price: 1,
},
customLabels: myCustomLabels
customLabels: myCustomLabels,
};
return Book.paginate(query, options).then((result) => {
expect(result.docs).to.have.length(10);

@@ -362,4 +359,4 @@ expect(result.docs[0].title).to.equal('Book #41');

title: {
$in: [/Book/i]
}
$in: [/Book/i],
},
};

@@ -377,3 +374,3 @@

hasPrevPage: 'hasPrevious',
hasNextPage: 'hasNext'
hasNextPage: 'hasNext',
};

@@ -383,3 +380,3 @@

sort: {
_id: 1
_id: 1,
},

@@ -390,5 +387,5 @@ limit: 10,

title: 1,
price: 1
price: 1,
},
customLabels: myCustomLabels
customLabels: myCustomLabels,
};

@@ -413,4 +410,4 @@ return Book.paginate(query, options).then((result) => {

title: {
$in: [/Book/i]
}
$in: [/Book/i],
},
};

@@ -421,3 +418,3 @@

docs: 'itemsList',
totalDocs: 'total'
totalDocs: 'total',
};

@@ -427,3 +424,3 @@

sort: {
_id: 1
_id: 1,
},

@@ -434,5 +431,5 @@ limit: 10,

title: 1,
price: 1
price: 1,
},
customLabels: myCustomLabels
customLabels: myCustomLabels,
};

@@ -450,6 +447,4 @@ return Book.paginate(query, options).then((result) => {

loc: {
$nearSphere:
[ 50, 50 ]
}
$nearSphere: [50, 50],
},
};

@@ -460,3 +455,3 @@

docs: 'itemsList',
totalDocs: 'total'
totalDocs: 'total',
};

@@ -466,3 +461,3 @@

sort: {
_id: 1
_id: 1,
},

@@ -473,6 +468,6 @@ limit: 10,

title: 1,
price: 1
price: 1,
},
forceCountFn: true,
customLabels: myCustomLabels
forceCountFn: true,
customLabels: myCustomLabels,
};

@@ -487,8 +482,8 @@ return Book.paginate(query, options).then((result) => {

title: {
$in: [/Book/i]
}
$in: [/Book/i],
},
};
var options = {
pagination: false
pagination: false,
};

@@ -507,3 +502,2 @@

expect(result.totalPages).to.equal(1);
});

@@ -521,2 +515,38 @@ });

it('count Custom Fn works', function (done) {
Book.paginate(
{},
{
useCustomCountFn: function () {
return 100;
},
},
function (err, result) {
expect(err).to.be.null;
expect(result).to.be.an.instanceOf(Object);
assert.isNumber(result.totalDocs, 'totalDocs is a number');
expect(result.totalDocs).to.equal(100);
done();
}
);
});
it('count Custom Fn with Promise return works', function (done) {
Book.paginate(
{},
{
useCustomCountFn: function () {
return Promise.resolve(100);
},
},
function (err, result) {
expect(err).to.be.null;
expect(result).to.be.an.instanceOf(Object);
assert.isNumber(result.totalDocs, 'totalDocs is a number');
expect(result.totalDocs).to.equal(100);
done();
}
);
});
after(function (done) {

@@ -529,3 +559,2 @@ mongoose.connection.db.dropDatabase(done);

});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc