Socket
Socket
Sign inDemoInstall

mongo-cursor-pagination

Package Overview
Dependencies
9
Maintainers
16
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.3.1 to 7.4.0

12

CHANGELOG.md

@@ -0,1 +1,13 @@

## [7.4.0](https://github.com/mixmaxhq/mongo-cursor-pagination/compare/v7.3.1...v7.4.0) (2021-03-08)
### Features
* **mongoose-plugin:** add search function ([0efd73c](https://github.com/mixmaxhq/mongo-cursor-pagination/commit/0efd73c9a5e53887226a4a1d2b61605a0e168514))
### Bug Fixes
* skip bad commit message ([4c85357](https://github.com/mixmaxhq/mongo-cursor-pagination/commit/4c85357f1079c6f73877ba6775b2eb6ad962c422))
### [7.3.1](https://github.com/mixmaxhq/mongo-cursor-pagination/compare/v7.3.0...v7.3.1) (2020-08-10)

@@ -2,0 +14,0 @@

34

dist/node/mongoose.plugin.js
const find = require('./find');
const search = require('./search');
const _ = require('underscore');

@@ -9,2 +10,3 @@

* @param {string} options.name name of the function.
* @param {string} options.searchFnName name of the function.
*/

@@ -15,6 +17,20 @@

* paginate function
* @param {Object} param required parameter
* @param {Object} params required parameter
*/
const findFn = function (params) {
if (!this.collection) {
throw new Error('collection property not found');
}
const fn = function (param) {
params = _.extend({}, params);
return find(this.collection, params);
};
/**
* search function
* @param {String} searchString String to search on. Required parameter
* @param {Object} params
*/
const searchFn = function (searchString, params) {
if (!this.collection) {

@@ -24,12 +40,18 @@ throw new Error('collection property not found');

param = _.extend({}, param);
params = _.extend({}, params);
return find(this.collection, param);
return search(this.collection, searchString, params);
};
if (options && options.name) {
schema.statics[options.name] = fn;
schema.statics[options.name] = findFn;
} else {
schema.statics.paginate = fn;
schema.statics.paginate = findFn;
}
if (options && options.searchFnName) {
schema.statics[options.searchFnName] = searchFn;
} else {
schema.statics.search = searchFn;
}
};

12

package.json
{
"name": "mongo-cursor-pagination",
"version": "7.3.1",
"version": "7.4.0",
"description": "Make it easy to return cursor-paginated results from a Mongo collection",

@@ -18,3 +18,3 @@ "main": "index.js",

"prepublishOnly": "npm run babelBuild && if [ \"$CI\" = '' ]; then node -p 'JSON.parse(process.env.npm_package_config_manualPublishMessage)'; exit 1; fi",
"semantic-release": "SEMANTIC_COMMITLINT_SKIP=5ed5489,e2ab709,187f1fe,0dcc73f semantic-release",
"semantic-release": "SEMANTIC_COMMITLINT_SKIP=5ed5489,e2ab709,187f1fe,0dcc73f,6d15fe5 semantic-release",
"test": "DRIVER=mongoist jest && DRIVER=native jest"

@@ -44,3 +44,3 @@ },

"bson": "^4.1.0",
"object-path": "^0.11.4",
"object-path": "^0.11.5",
"projection-utils": "^1.1.0",

@@ -60,3 +60,3 @@ "semver": "^5.4.1",

"eslint": "^6.8.0",
"eslint-config-mixmax": "^3.4.0",
"eslint-config-mixmax": "^4.11.2",
"jest": "^26.0.1",

@@ -67,5 +67,5 @@ "mockgoose": "^8.0.4",

"mongoist": "2.3.0",
"mongoose": "5.7.5",
"mongoose": "5.11.10",
"prettier": "^1.19.1",
"semantic-release": "^17.0.7"
"semantic-release": "^17.2.3"
},

@@ -72,0 +72,0 @@ "engines": {

# mongo-cursor-pagination
[![Build Status](https://travis-ci.org/mixmaxhq/mongo-cursor-pagination.svg?branch=master)](https://travis-ci.org/mixmaxhq/mongo-cursor-pagination)
This module aids in implementing "cursor-based" pagination using Mongo range queries or relevancy-based search results. __This module is currently used in production for the [Mixmax API](https://developer.mixmax.com) to return millions of results a day__.
This module aids in implementing "cursor-based" pagination using Mongo range queries or relevancy-based search results. **This module is currently used in production for the [Mixmax API](https://developer.mixmax.com) to return millions of results a day**.
### New
* [Now Supports Mongoose](https://github.com/mixmaxhq/mongo-cursor-pagination#with-mongoose)
- [Now Supports Mongoose](https://github.com/mixmaxhq/mongo-cursor-pagination#with-mongoose)
## Background

@@ -23,5 +25,5 @@

* [Twitter](https://dev.twitter.com/overview/api/cursoring)
* [Stripe](https://stripe.com/docs/api#pagination-starting_after)
* [Facebook](https://developers.facebook.com/docs/graph-api/using-graph-api/#cursors)
- [Twitter](https://dev.twitter.com/overview/api/cursoring)
- [Stripe](https://stripe.com/docs/api#pagination-starting_after)
- [Facebook](https://developers.facebook.com/docs/graph-api/using-graph-api/#cursors)

@@ -74,15 +76,20 @@ ## Install

async function findExample() {
await db.collection('myobjects').insertMany([{
counter: 1
}, {
counter: 2
}, {
counter: 3
}, {
counter: 4
}]);
await db.collection('myobjects').insertMany([
{
counter: 1,
},
{
counter: 2,
},
{
counter: 3,
},
{
counter: 4,
},
]);
// Query the first page.
let result = await MongoPaging.find(db.collection('myobjects'), {
limit: 2
limit: 2,
});

@@ -94,3 +101,3 @@ console.log(result);

limit: 2,
next: result.next // This queries the next page
next: result.next, // This queries the next page
});

@@ -135,12 +142,8 @@ console.log(result);

const counter = mongoose.model('counter',
counterSchema);
const counter = mongoose.model('counter', counterSchema);
// default function is "paginate"
counter.paginate({ limit : 10 })
.then((result) => {
counter.paginate({ limit: 10 }).then((result) => {
console.log(result);
});
```

@@ -171,3 +174,19 @@

You can also use the search function (as described below) like so;
```js
// this will add paginate function.
counterSchema.plugin(MongoPaging.mongoosePlugin);
// give custom function name
// counterSchema.plugin(MongoPaging.mongoosePlugin, { searchFnName: 'searchFN' });
const counter = mongoose.model('counter', counterSchema);
// default function is "paginate"
counter.search('dog', { limit: 10 }).then((result) => {
console.log(result);
});
```
### search()

@@ -207,12 +226,16 @@

await db.collection('myobjects').ensureIndex({
mytext: 'text'
mytext: 'text',
});
await db.collection('myobjects').insertMany([{
mytext: 'dogs'
}, {
mytext: 'dogs cats'
}, {
mytext: 'dogs cats pigs'
}]);
await db.collection('myobjects').insertMany([
{
mytext: 'dogs',
},
{
mytext: 'dogs cats',
},
{
mytext: 'dogs cats pigs',
},
]);

@@ -222,5 +245,5 @@ // Query the first page.

fields: {
mytext: 1
mytext: 1,
},
limit: 2
limit: 2,
});

@@ -232,3 +255,3 @@ console.log(result);

limit: 2,
next: result.next // This queries the next page
next: result.next, // This queries the next page
});

@@ -323,3 +346,2 @@ console.log(result);

### Indexes for sorting

@@ -347,3 +369,3 @@

city: 1,
_id: 1
_id: 1,
});

@@ -358,2 +380,2 @@ ```

* Add support to `search()` to query previous pages.
- Add support to `search()` to query previous pages.
const find = require('./find');
const search = require('./search');
const _ = require('underscore');

@@ -9,2 +10,3 @@

* @param {string} options.name name of the function.
* @param {string} options.searchFnName name of the function.
*/

@@ -15,6 +17,20 @@

* paginate function
* @param {Object} param required parameter
* @param {Object} params required parameter
*/
const findFn = function(params) {
if (!this.collection) {
throw new Error('collection property not found');
}
const fn = function(param) {
params = _.extend({}, params);
return find(this.collection, params);
};
/**
* search function
* @param {String} searchString String to search on. Required parameter
* @param {Object} params
*/
const searchFn = function(searchString, params) {
if (!this.collection) {

@@ -24,12 +40,18 @@ throw new Error('collection property not found');

param = _.extend({}, param);
params = _.extend({}, params);
return find(this.collection, param);
return search(this.collection, searchString, params);
};
if (options && options.name) {
schema.statics[options.name] = fn;
schema.statics[options.name] = findFn;
} else {
schema.statics.paginate = fn;
schema.statics.paginate = findFn;
}
if (options && options.searchFnName) {
schema.statics[options.searchFnName] = searchFn;
} else {
schema.statics.search = searchFn;
}
};
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc