[PR #5686] [MERGED] fix(adapters): mongodb id issue #6159

Closed
opened 2026-03-13 12:49:37 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5686
Author: @okisdev
Created: 10/30/2025
Status: Merged
Merged: 10/31/2025
Merged by: @himself65

Base: canaryHead: fix(adapters)/mongodb-id-issue


📝 Commits (6)

  • c7819d9 fix(adapters): mongodb id issue
  • 669e568 fix(adapters): mongodb id issue
  • d224fee fix(adapters): mongodb id issue
  • 20ec854 fix(adapters): mongodb id issue
  • 557997c fix(adapters): mongodb id issue
  • 3cd8c5b Merge branch 'canary' into fix(adapters)/mongodb-id-issue

📊 Changes

4 files changed (+179 additions, -33 deletions)

View changed files

📝 packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts (+51 -5)
📝 packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts (+38 -28)
📝 packages/better-auth/src/adapters/tests/normal.ts (+42 -0)
📝 packages/better-auth/src/plugins/admin/admin.test.ts (+48 -0)

📄 Description

This PR adds serializeID to MongoDB actions: gt, gte, lt, lte and ne to ensure the id is converted to ObjectId for future actions.

This PR fixes #5143


Summary by cubic

Fixes MongoDB id comparisons by converting values to ObjectId for gt/gte/lt/lte/ne, and improves Prisma where handling for nulls and in/not_in. Filters using id or _id now return correct results, including in Admin listUsers.

  • Bug Fixes
    • Use serializeID for gt/gte/lt/lte/ne when comparing id/_id (skips null/undefined).
    • Prisma: ignore ne with null, filter nulls in in/not_in arrays, and handle empty arrays safely.
    • Add tests for adapter findMany (id/_id ne, ne null, in with null) and Admin listUsers with id/_id ne.

Written for commit 3cd8c5b. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5686 **Author:** [@okisdev](https://github.com/okisdev) **Created:** 10/30/2025 **Status:** ✅ Merged **Merged:** 10/31/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix(adapters)/mongodb-id-issue` --- ### 📝 Commits (6) - [`c7819d9`](https://github.com/better-auth/better-auth/commit/c7819d9b199383d1ca77112bf855e7507ec2e3cd) fix(adapters): mongodb id issue - [`669e568`](https://github.com/better-auth/better-auth/commit/669e568778de116d6b62b48e9bf60e2ddac3fc72) fix(adapters): mongodb id issue - [`d224fee`](https://github.com/better-auth/better-auth/commit/d224feedf6743675651c06d8f80a66545da2fbdb) fix(adapters): mongodb id issue - [`20ec854`](https://github.com/better-auth/better-auth/commit/20ec854bdff22b577267d2758149b5dff3335893) fix(adapters): mongodb id issue - [`557997c`](https://github.com/better-auth/better-auth/commit/557997c7d0dfbb42f0eb8c622a1a43539df2cc1d) fix(adapters): mongodb id issue - [`3cd8c5b`](https://github.com/better-auth/better-auth/commit/3cd8c5b26adbffc91e97f8a425c30261cf526492) Merge branch 'canary' into fix(adapters)/mongodb-id-issue ### 📊 Changes **4 files changed** (+179 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts` (+51 -5) 📝 `packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts` (+38 -28) 📝 `packages/better-auth/src/adapters/tests/normal.ts` (+42 -0) 📝 `packages/better-auth/src/plugins/admin/admin.test.ts` (+48 -0) </details> ### 📄 Description This PR adds `serializeID` to MongoDB actions: `gt`, `gte`, `lt`, `lte` and `ne` to ensure the id is converted to ObjectId for future actions. This PR fixes #5143 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes MongoDB id comparisons by converting values to ObjectId for gt/gte/lt/lte/ne, and improves Prisma where handling for nulls and in/not_in. Filters using id or _id now return correct results, including in Admin listUsers. - **Bug Fixes** - Use serializeID for gt/gte/lt/lte/ne when comparing id/_id (skips null/undefined). - Prisma: ignore ne with null, filter nulls in in/not_in arrays, and handle empty arrays safely. - Add tests for adapter findMany (id/_id ne, ne null, in with null) and Admin listUsers with id/_id ne. <sup>Written for commit 3cd8c5b. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:49:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6159