mongo-cursor-pagination
Advanced tools
Comparing version 7.6.1 to 7.7.0
@@ -0,1 +1,14 @@ | ||
## [7.7.0](https://github.com/mixmaxhq/mongo-cursor-pagination/compare/v7.6.1...v7.7.0) (2022-08-16) | ||
### Features | ||
* allow collation as arg on find and aggregate ([cdfcfcb](https://github.com/mixmaxhq/mongo-cursor-pagination/commit/cdfcfcbf355f177d0589341f603b0458e4fc5c64)) | ||
* turn global collation off for single query ([c2ff6da](https://github.com/mixmaxhq/mongo-cursor-pagination/commit/c2ff6dae5824820414d5286f91d0cd7eedf0ba90)) | ||
### Bug Fixes | ||
* skip commit with wrong scope ([#322](https://github.com/mixmaxhq/mongo-cursor-pagination/issues/322)) ([e2729ac](https://github.com/mixmaxhq/mongo-cursor-pagination/commit/e2729ac584a483f28e1275f70eb7ebd8ec44556b)) | ||
### [7.6.1](https://github.com/mixmaxhq/mongo-cursor-pagination/compare/v7.6.0...v7.6.1) (2021-11-18) | ||
@@ -2,0 +15,0 @@ |
@@ -39,2 +39,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"); }); }; } | ||
* -options {Object} Aggregation options | ||
* -collation {Object} An optional collation to provide to the mongo query. E.g. { locale: 'en', strength: 2 }. When null, disables the global collation. | ||
*/ | ||
@@ -74,9 +75,8 @@ module.exports = (() => { | ||
* | ||
* If using a global collation setting, ensure that your collections' indexes (that index upon string fields) | ||
* have been created with the same collation option; if this isn't the case, your queries will be unable to | ||
* take advantage of any indexes. | ||
* | ||
* See mongo documentation: https://docs.mongodb.com/manual/reference/collation/#collation-and-index-use | ||
* If using collation, check the README: | ||
* https://github.com/mixmaxhq/mongo-cursor-pagination#important-note-regarding-collation | ||
*/ | ||
if (config.COLLATION) options.collation = config.COLLATION; | ||
const isCollationNull = params.collation === null; | ||
const collation = params.collation || config.COLLATION; | ||
if (collation && !isCollationNull) options.collation = collation; | ||
@@ -83,0 +83,0 @@ // Support both the native 'mongodb' driver and 'mongoist'. See: |
@@ -31,2 +31,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"); }); }; } | ||
* -hint {String} An optional index hint to provide to the mongo query | ||
* -collation {Object} An optional collation to provide to the mongo query. E.g. { locale: 'en', strength: 2 }. When null, disables the global collation. | ||
*/ | ||
@@ -51,9 +52,8 @@ module.exports = (() => { | ||
* | ||
* If using a global collation setting, ensure that your collections' indexes (that index upon string fields) | ||
* have been created with the same collation option; if this isn't the case, your queries will be unable to | ||
* take advantage of any indexes. | ||
* | ||
* See mongo documentation: https://docs.mongodb.com/manual/reference/collation/#collation-and-index-use | ||
* If using collation, check the README: | ||
* https://github.com/mixmaxhq/mongo-cursor-pagination#important-note-regarding-collation | ||
*/ | ||
const collatedQuery = config.COLLATION ? query.collation(config.COLLATION) : query; | ||
const isCollationNull = params.collation === null; | ||
const collation = params.collation || config.COLLATION; | ||
const collatedQuery = collation && !isCollationNull ? query.collation(collation) : query; | ||
// Query one more element to see if there's another page. | ||
@@ -60,0 +60,0 @@ const cursor = collatedQuery.sort($sort).limit(params.limit + 1); |
{ | ||
"name": "mongo-cursor-pagination", | ||
"version": "7.6.1", | ||
"version": "7.7.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,6d15fe5 semantic-release", | ||
"semantic-release": "SEMANTIC_COMMITLINT_SKIP=5ed5489,e2ab709,187f1fe,0dcc73f,6d15fe5,7a05f30 semantic-release", | ||
"test": "DRIVER=mongoist jest && DRIVER=native jest" | ||
@@ -21,0 +21,0 @@ }, |
@@ -332,3 +332,3 @@ # mongo-cursor-pagination | ||
If using a global collation setting, ensure that your collections' indexes (that index upon string fields) | ||
If using a global collation setting, or a query with collation argument, ensure that your collections' indexes (that index upon string fields) | ||
have been created with the same collation option; if this isn't the case, your queries will be unable to | ||
@@ -339,2 +339,24 @@ take advantage of any indexes. | ||
For instance, given the following index: | ||
```js | ||
db.people.createIndex({ city: 1, _id: 1 }); | ||
``` | ||
When executing the query: | ||
```js | ||
MongoPaging.find(db.people, { | ||
limit: 25, | ||
paginatedField: 'city' | ||
collation: { locale: 'en' }, | ||
}); | ||
``` | ||
The index won't be used for the query because it doesn't include the collation used. The index should added as such: | ||
```js | ||
db.people.createIndex({ city: 1, _id: 1 }, { collation: { locale: 'en' } }); | ||
``` | ||
### Indexes for sorting | ||
@@ -359,3 +381,3 @@ | ||
```js | ||
db.people.ensureIndex({ | ||
db.people.createIndex({ | ||
name: 1, | ||
@@ -362,0 +384,0 @@ city: 1, |
@@ -37,2 +37,3 @@ const _ = require('underscore'); | ||
* -options {Object} Aggregation options | ||
* -collation {Object} An optional collation to provide to the mongo query. E.g. { locale: 'en', strength: 2 }. When null, disables the global collation. | ||
*/ | ||
@@ -69,9 +70,8 @@ module.exports = async function aggregate(collection, params) { | ||
* | ||
* If using a global collation setting, ensure that your collections' indexes (that index upon string fields) | ||
* have been created with the same collation option; if this isn't the case, your queries will be unable to | ||
* take advantage of any indexes. | ||
* | ||
* See mongo documentation: https://docs.mongodb.com/manual/reference/collation/#collation-and-index-use | ||
* If using collation, check the README: | ||
* https://github.com/mixmaxhq/mongo-cursor-pagination#important-note-regarding-collation | ||
*/ | ||
if (config.COLLATION) options.collation = config.COLLATION; | ||
const isCollationNull = params.collation === null; | ||
const collation = params.collation || config.COLLATION; | ||
if (collation && !isCollationNull) options.collation = collation; | ||
@@ -78,0 +78,0 @@ // Support both the native 'mongodb' driver and 'mongoist'. See: |
@@ -29,2 +29,3 @@ const _ = require('underscore'); | ||
* -hint {String} An optional index hint to provide to the mongo query | ||
* -collation {Object} An optional collation to provide to the mongo query. E.g. { locale: 'en', strength: 2 }. When null, disables the global collation. | ||
*/ | ||
@@ -49,9 +50,8 @@ module.exports = async function(collection, params) { | ||
* | ||
* If using a global collation setting, ensure that your collections' indexes (that index upon string fields) | ||
* have been created with the same collation option; if this isn't the case, your queries will be unable to | ||
* take advantage of any indexes. | ||
* | ||
* See mongo documentation: https://docs.mongodb.com/manual/reference/collation/#collation-and-index-use | ||
* If using collation, check the README: | ||
* https://github.com/mixmaxhq/mongo-cursor-pagination#important-note-regarding-collation | ||
*/ | ||
const collatedQuery = config.COLLATION ? query.collation(config.COLLATION) : query; | ||
const isCollationNull = params.collation === null; | ||
const collation = params.collation || config.COLLATION; | ||
const collatedQuery = collation && !isCollationNull ? query.collation(collation) : query; | ||
// Query one more element to see if there's another page. | ||
@@ -58,0 +58,0 @@ const cursor = collatedQuery.sort($sort).limit(params.limit + 1); |
85087
393