[PR #5384] [MERGED] feat(mongodb): support string IDs over ObjectIDs #31572

Closed
opened 2026-04-17 22:28:14 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5384
Author: @ping-maxwell
Created: 10/17/2025
Status: Merged
Merged: 11/3/2025
Merged by: @Bekacru

Base: canaryHead: feat/mongo-support-string-id


📝 Commits (10+)

  • eee27c8 feat(MongoDB): Support string IDs over ObjectIDs
  • f791466 chore: lint
  • 6269560 Update packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts
  • 60e2aae chore: lint
  • 77ccda0 update: docs
  • a33f051 Merge branch 'canary' into feat/mongo-support-string-id
  • 2ef0820 Merge branch 'canary' into feat/mongo-support-string-id
  • ac8cb95 Merge branch 'canary' into feat/mongo-support-string-id
  • 2360883 fix: revert to old system
  • 0743771 Merge branch 'canary' into feat/mongo-support-string-id

📊 Changes

6 files changed (+95 additions, -31 deletions)

View changed files

📝 docs/content/docs/adapters/mongo.mdx (+1 -1)
📝 packages/better-auth/src/adapters/create-test-suite.ts (+48 -4)
📝 packages/better-auth/src/adapters/mongodb-adapter/adapter.mongo-db.test.ts (+4 -4)
📝 packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts (+27 -19)
📝 packages/better-auth/src/adapters/test-adapter.ts (+7 -1)
📝 packages/better-auth/src/adapters/tests/normal.ts (+8 -2)

📄 Description

In the past we've supported this (albeit I wasn't aware of this), since my PR to refactor the adapter tests I made the mongo adapter more strict to where users who used generateId were getting their IDs saved as ObjectIDs instead of pure strings unlike older versions.

This PR allows the old way of things.

closes https://github.com/better-auth/better-auth/issues/5377


Summary by cubic

Adds support for string IDs in the MongoDB adapter by honoring a custom generateId and skipping ObjectId conversion. Updates the test harness and adapter logic to work cleanly with both ObjectId and string modes.

  • New Features

    • Adapter skips ObjectId conversion when a custom generateId is provided, storing and returning string IDs.
    • Updated ID handling in serialization and where-clause conversion to respect string IDs.
  • Refactors

    • Test harness now supports customIdGenerator, transformIdOutput, and transformGeneratedModel.
    • Normal tests compare transformed models to match adapter output.

Written for commit d5c537b7bb. 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/5384 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 10/17/2025 **Status:** ✅ Merged **Merged:** 11/3/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/mongo-support-string-id` --- ### 📝 Commits (10+) - [`eee27c8`](https://github.com/better-auth/better-auth/commit/eee27c832b167df7179a05fb4b2617f4e35bc73a) feat(MongoDB): Support string IDs over ObjectIDs - [`f791466`](https://github.com/better-auth/better-auth/commit/f7914668cb93d57c4f0c3172c6c141e14ce3ea81) chore: lint - [`6269560`](https://github.com/better-auth/better-auth/commit/626956083eb86cb772220fcf824684ee3d0471e6) Update packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts - [`60e2aae`](https://github.com/better-auth/better-auth/commit/60e2aae0c07198700fc3267be6746d5059a8ee5e) chore: lint - [`77ccda0`](https://github.com/better-auth/better-auth/commit/77ccda04606b6e9dabbcda6b13afed4db7b56bea) update: docs - [`a33f051`](https://github.com/better-auth/better-auth/commit/a33f051e1a53ca3409257b1d2bc9378c7da35ffb) Merge branch 'canary' into feat/mongo-support-string-id - [`2ef0820`](https://github.com/better-auth/better-auth/commit/2ef0820319d7fb494ab49763f6a6fc00c4334e8b) Merge branch 'canary' into feat/mongo-support-string-id - [`ac8cb95`](https://github.com/better-auth/better-auth/commit/ac8cb95f29f3fe55a82f0178429b03363e9ad245) Merge branch 'canary' into feat/mongo-support-string-id - [`2360883`](https://github.com/better-auth/better-auth/commit/23608836426f882ea1f09a6ab6309e089a645847) fix: revert to old system - [`0743771`](https://github.com/better-auth/better-auth/commit/074377141889989514cb6ea275aac3c421b520de) Merge branch 'canary' into feat/mongo-support-string-id ### 📊 Changes **6 files changed** (+95 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/adapters/mongo.mdx` (+1 -1) 📝 `packages/better-auth/src/adapters/create-test-suite.ts` (+48 -4) 📝 `packages/better-auth/src/adapters/mongodb-adapter/adapter.mongo-db.test.ts` (+4 -4) 📝 `packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts` (+27 -19) 📝 `packages/better-auth/src/adapters/test-adapter.ts` (+7 -1) 📝 `packages/better-auth/src/adapters/tests/normal.ts` (+8 -2) </details> ### 📄 Description In the past we've supported this (albeit I wasn't aware of this), since my PR to refactor the adapter tests I made the mongo adapter more strict to where users who used `generateId` were getting their IDs saved as ObjectIDs instead of pure strings unlike older versions. This PR allows the old way of things. closes https://github.com/better-auth/better-auth/issues/5377 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds support for string IDs in the MongoDB adapter by honoring a custom generateId and skipping ObjectId conversion. Updates the test harness and adapter logic to work cleanly with both ObjectId and string modes. - **New Features** - Adapter skips ObjectId conversion when a custom generateId is provided, storing and returning string IDs. - Updated ID handling in serialization and where-clause conversion to respect string IDs. - **Refactors** - Test harness now supports customIdGenerator, transformIdOutput, and transformGeneratedModel. - Normal tests compare transformed models to match adapter output. <sup>Written for commit d5c537b7bb7967e77797ef2cd5cc1286cae9da21. 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-04-17 22:28:14 -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#31572