Skip to content

Commit 78a27ab

Browse files
fix(db-mongodb): update mongoose-paginate-v2 to fix collation pagination (#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>
1 parent 4e48706 commit 78a27ab

3 files changed

Lines changed: 1878 additions & 1657 deletions

File tree

packages/db-mongodb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
},
5454
"dependencies": {
5555
"mongoose": "8.15.1",
56-
"mongoose-paginate-v2": "1.8.5",
56+
"mongoose-paginate-v2": "1.9.4",
5757
"prompts": "2.4.2",
5858
"uuid": "10.0.0"
5959
},

packages/db-mongodb/src/queryDrafts.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,6 @@ export const queryDrafts: QueryDrafts = async function queryDrafts(
123123
}),
124124
)
125125
}
126-
} else if (!useEstimatedCount && this.collation) {
127-
// Workaround for mongoose-paginate-v2 bug: chaining .collation() on countDocuments breaks
128-
// session context in transactions (mongoose 8.x). Provide custom count function that passes
129-
// collation as an option instead. See: https://github.com/aravindnc/mongoose-paginate-v2/pull/240
130-
// TODO: Remove this workaround once mongoose-paginate-v2 is updated with the fix.
131-
paginationOptions.useCustomCountFn = () => {
132-
return Promise.resolve(
133-
Model.countDocuments(versionQuery, {
134-
collation: paginationOptions.collation,
135-
session,
136-
}),
137-
)
138-
}
139126
}
140127

141128
if (limit && limit > 0) {
@@ -158,7 +145,6 @@ export const queryDrafts: QueryDrafts = async function queryDrafts(
158145
versions: true,
159146
})
160147

161-
// build join aggregation
162148
if (aggregate || sortAggregation.length > 0) {
163149
result = await aggregatePaginate({
164150
adapter: this,

0 commit comments

Comments
 (0)