mongo-cursor-pagination
Advanced tools
Comparing version
## Changelog | ||
* 7.2.0 Add support for `COLLATION` configuration parameter. | ||
* 7.1.0 Add support for `aggregate`. | ||
* 7.0.1 Update base64-url to fix security issue (https://github.com/mixmaxhq/mongo-cursor-pagination/pull/41 - thanks @pwiebe). | ||
@@ -6,0 +8,0 @@ |
@@ -6,2 +6,3 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
const { prepareResponse, generateSort, generateCursorQuery } = require('./utils/query'); | ||
const config = require('./config'); | ||
@@ -65,2 +66,4 @@ /** | ||
let options = config.COLLATION ? { collation: config.COLLATION } : undefined; | ||
// Support both the native 'mongodb' driver and 'mongoist'. See: | ||
@@ -70,3 +73,3 @@ // https://www.npmjs.com/package/mongoist#cursor-operations | ||
let results = yield collection[aggregateMethod](params.aggregation).toArray(); | ||
let results = yield collection[aggregateMethod](params.aggregation, options).toArray(); | ||
@@ -73,0 +76,0 @@ return prepareResponse(results, params); |
@@ -6,2 +6,3 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
const { prepareResponse, generateSort, generateCursorQuery } = require('./utils/query'); | ||
const config = require('./config'); | ||
@@ -43,3 +44,5 @@ /** | ||
const results = yield collection[findMethod]({ $and: [cursorQuery, params.query] }, params.fields).sort($sort).limit(params.limit + 1) // Query one more element to see if there's another page. | ||
const query = collection[findMethod]({ $and: [cursorQuery, params.query] }, params.fields); | ||
const collatedQuery = config.COLLATION ? query.collation(config.COLLATION) : query; | ||
const results = yield collatedQuery.sort($sort).limit(params.limit + 1) // Query one more element to see if there's another page. | ||
.toArray(); | ||
@@ -46,0 +49,0 @@ |
{ | ||
"name": "mongo-cursor-pagination", | ||
"version": "7.1.0", | ||
"version": "7.2.0", | ||
"description": "Make it easy to return cursor-paginated results from a Mongo collection", | ||
@@ -58,3 +58,3 @@ "main": "index.js", | ||
"mongodb-memory-server": "^1.6.1", | ||
"mongoist": "1.4.3", | ||
"mongoist": "2.3.0", | ||
"mongoose": "5.0.15" | ||
@@ -61,0 +61,0 @@ }, |
@@ -302,2 +302,7 @@ # mongo-cursor-pagination | ||
### Alphabetical sorting | ||
The collation to use for alphabetical sorting, both with `find` and `aggregate`, can be selected by setting `mongoPaging.config.COLLATION`. If this parameter is | ||
not set, no collation will be provided for the aggregation/cursor, which means that MongoDB will use whatever collation was set for the collection. | ||
### Indexes for sorting | ||
@@ -304,0 +309,0 @@ |
const _ = require('underscore'); | ||
const sanitizeParams = require('./utils/sanitizeParams'); | ||
const { prepareResponse, generateSort, generateCursorQuery } = require('./utils/query'); | ||
const config = require('./config'); | ||
@@ -62,2 +63,4 @@ /** | ||
let options = config.COLLATION ? { collation: config.COLLATION } : undefined; | ||
// Support both the native 'mongodb' driver and 'mongoist'. See: | ||
@@ -67,5 +70,5 @@ // https://www.npmjs.com/package/mongoist#cursor-operations | ||
let results = await collection[aggregateMethod](params.aggregation).toArray(); | ||
let results = await collection[aggregateMethod](params.aggregation, options).toArray(); | ||
return prepareResponse(results, params); | ||
}; |
const _ = require('underscore'); | ||
const sanitizeParams = require('./utils/sanitizeParams'); | ||
const { prepareResponse, generateSort, generateCursorQuery } = require('./utils/query'); | ||
const config = require('./config'); | ||
@@ -42,3 +43,5 @@ /** | ||
const results = await collection[findMethod]({ $and: [cursorQuery, params.query] }, params.fields) | ||
const query = collection[findMethod]({ $and: [cursorQuery, params.query] }, params.fields); | ||
const collatedQuery = config.COLLATION ? query.collation(config.COLLATION) : query; | ||
const results = await collatedQuery | ||
.sort($sort) | ||
@@ -45,0 +48,0 @@ .limit(params.limit + 1) // Query one more element to see if there's another page. |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
74015
1.31%1278
0.79%340
1.49%1
-50%31
-3.12%