mixmaxhq / mongo-cursor-pagination

Cursor-based pagination for Mongo
https://www.mixmax.com/careers
MIT License
229 stars 72 forks source link

feat: allow collation as arg on find and aggregate #320

Closed raphaelbs closed 2 years ago

raphaelbs commented 2 years ago

Changes Made

Enable the use of a custom collation for a single find or aggregate call.

Why: Using the default config.COLLATION means we must re-index the collections to ensure our indexes match the collation. Conversely, we could use the static configuration for a single call but it opens a breach for race-condition issues:

paging.config.COLLATION = { locale: 'en' };
const results = await paging.find(collection, { ... })
// if any other `.find` or `.aggregate` methods were called before the `delete` line below,
// they will use the collation set above, which may not be desired;
delete paging.config.COLLATION;

With the PRs code, we can use:

const results = await paging.find(collection, { ..., collation: { locale: 'en' } })

Potential Risks

Test Plan

Checklist

raphaelbs commented 2 years ago

@adborroto thanks for the suggestion. Added on https://github.com/mixmaxhq/mongo-cursor-pagination/pull/320/commits/7a05f30859f03b1381957ce25358ecc4b9ce362d

mixmax-bot commented 2 years ago

:tada: This PR is included in version 7.7.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: