fix(db-mongodb): fix pagination with collation in transactions#15990
Merged
JarrodMFlesch merged 1 commit intomainfrom Mar 20, 2026
Merged
fix(db-mongodb): fix pagination with collation in transactions#15990JarrodMFlesch merged 1 commit intomainfrom
JarrodMFlesch merged 1 commit intomainfrom
Conversation
When using MongoDB collation with sessions in transactions, mongoose-paginate-v2 chains `.collation()` which breaks session context in mongoose 8.x, causing incorrect totalDocs counts. Changes: - Add custom count function when collation is enabled to pass collation as an option instead of chaining - Use config.localization.defaultLocale for collation locale fallback instead of hardcoded 'en' - Add collation support to count functions Upstream fix submitted: aravindnc/mongoose-paginate-v2#240 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
r1tsuu
approved these changes
Mar 19, 2026
Contributor
|
🚀 This is included in version v3.80.0 |
2 tasks
JarrodMFlesch
added a commit
that referenced
this pull request
Apr 7, 2026
…ion (#16049) ## Summary - Upgrades mongoose-paginate-v2 from 1.8.5 to 1.9.4 with my [fix](aravindnc/mongoose-paginate-v2#241) - Removes workaround code using `useCustomCountFn` ### Fixes included in 1.9.4: - **Collation + session in transactions** - chaining `.collation()` on `countDocuments` was breaking session context - **limit in options.options** - was being passed to `countDocuments`, causing incorrect `totalDocs` count ## Test plan - [x] `pnpm test:int database` - all 160 tests pass - [x] Collation tests specifically verified: - `ensure mongodb respects collation when using collection in the config` - `ensure mongodb collation works with draft pagination without sort` Additional context #15990 --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
milamer
pushed a commit
to milamer/payload
that referenced
this pull request
Apr 20, 2026
…ion (payloadcms#16049) ## Summary - Upgrades mongoose-paginate-v2 from 1.8.5 to 1.9.4 with my [fix](aravindnc/mongoose-paginate-v2#241) - Removes workaround code using `useCustomCountFn` ### Fixes included in 1.9.4: - **Collation + session in transactions** - chaining `.collation()` on `countDocuments` was breaking session context - **limit in options.options** - was being passed to `countDocuments`, causing incorrect `totalDocs` count ## Test plan - [x] `pnpm test:int database` - all 160 tests pass - [x] Collation tests specifically verified: - `ensure mongodb respects collation when using collection in the config` - `ensure mongodb collation works with draft pagination without sort` Additional context payloadcms#15990 --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes incorrect
totalDocscount when using MongoDB collation with sessions in transactions.Problem
When
collationis enabled on the MongoDB adapter,mongoose-paginate-v2chains.collation()on queries which breaks session context in mongoose 8.x. This causes:totalDocs(returns limit value instead of actual count)Solution
useCustomCountFn) when collation is enabled to pass collation as an option instead of chainingconfig.localization.defaultLocalefor collation locale fallback instead of hardcoded'en'Upstream Fix
Submitted a fix to mongoose-paginate-v2: aravindnc/mongoose-paginate-v2#241
The workaround in this PR includes TODO comments indicating it can be removed once the upstream fix is merged and released.
Test plan