SIGN IN SIGN UP
payloadcms / payload UNCLAIMED

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.

0 0 16 TypeScript

fix(db-mongodb): fix pagination with collation in transactions (#15990)

## Summary

Fixes incorrect `totalDocs` count when using MongoDB collation with
sessions in transactions.

## Problem

When `collation` is enabled on the MongoDB adapter,
`mongoose-paginate-v2` chains `.collation()` on queries which breaks
session context in mongoose 8.x. This causes:
- Incorrect `totalDocs` (returns limit value instead of actual count)
- Transaction mismatch errors in some cases

## Solution

- Add custom count function (`useCustomCountFn`) 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 a fix to mongoose-paginate-v2:
https://github.com/aravindnc/mongoose-paginate-v2/pull/240

The workaround in this PR includes TODO comments indicating it can be
removed once the upstream fix is merged and released.

## Test plan

- [x] Added integration test that verifies collation works with draft
pagination
- [x] Existing database tests pass

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
J
Jarrod Flesch committed
5c935aa14b94fd4ebd9515328f0cfe6137d0c706
Parent: 67063ab
Committed by GitHub <noreply@github.com> on 3/20/2026, 2:25:54 PM