[PR #7977] [MERGED] fix(mongo-adapter): updating a FK id should store as ObjectID #7664

Closed
opened 2026-03-13 13:44:58 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7977
Author: @ping-maxwell
Created: 2/15/2026
Status: Merged
Merged: 2/15/2026
Merged by: @Bekacru

Base: canaryHead: fix/mong-update-id-removes-objectid


📝 Commits (8)

  • 5306d86 fix(mongo-adapter): updating a FK id should store as ObjectID
  • 5e2e742 Merge branch 'canary' into fix/mong-update-id-removes-objectid
  • 81714d9 Merge branch 'canary' into fix/mong-update-id-removes-objectid
  • 979aa37 chore: lint
  • 9ca9956 chore: fix
  • 2700e65 Merge branch 'canary' into fix/mong-update-id-removes-objectid
  • edeccf7 fix: other tests failing
  • 4f983c6 Merge branch 'canary' into fix/mong-update-id-removes-objectid

📊 Changes

2 files changed (+62 additions, -2 deletions)

View changed files

📝 e2e/adapter/test/mongo-adapter/adapter.mongo-db.test.ts (+55 -1)
📝 packages/mongo-adapter/src/mongodb-adapter.ts (+7 -1)

📄 Description

https://github.com/better-auth/better-auth/issues/7892


Summary by cubic

Fixes Mongo adapter updates to keep id and FK fields as ObjectId and avoid generating new ids during update. Prevents string FK values (e.g., session.userId) after updates.

  • Bug Fixes
    • Apply ObjectId coercion on create and update, preserving existing ObjectId values.
    • Add an e2e test suite verifying session.userId remains an ObjectId before and after update.

Written for commit 4f983c607d. Summary will update 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/7977 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 2/15/2026 **Status:** ✅ Merged **Merged:** 2/15/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/mong-update-id-removes-objectid` --- ### 📝 Commits (8) - [`5306d86`](https://github.com/better-auth/better-auth/commit/5306d86d4b828e68fad9de5c9eb7beae53e305db) fix(mongo-adapter): updating a FK id should store as ObjectID - [`5e2e742`](https://github.com/better-auth/better-auth/commit/5e2e742e05dbd9bdea9b97df674c5915a1f2f815) Merge branch 'canary' into fix/mong-update-id-removes-objectid - [`81714d9`](https://github.com/better-auth/better-auth/commit/81714d9400f683df5e2c867536b24e49cf88b324) Merge branch 'canary' into fix/mong-update-id-removes-objectid - [`979aa37`](https://github.com/better-auth/better-auth/commit/979aa372b0fb308dd9842a7e28fd684b2b2544b3) chore: lint - [`9ca9956`](https://github.com/better-auth/better-auth/commit/9ca99569ebbcd6221574382eddf3bf857c007007) chore: fix - [`2700e65`](https://github.com/better-auth/better-auth/commit/2700e657f17c215f7df0e9f42e9669eb293799fc) Merge branch 'canary' into fix/mong-update-id-removes-objectid - [`edeccf7`](https://github.com/better-auth/better-auth/commit/edeccf7335ef7ed3c5ff15da08d99c72d284c038) fix: other tests failing - [`4f983c6`](https://github.com/better-auth/better-auth/commit/4f983c607d5dc52a43c206c653c2c9874ffd11e0) Merge branch 'canary' into fix/mong-update-id-removes-objectid ### 📊 Changes **2 files changed** (+62 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `e2e/adapter/test/mongo-adapter/adapter.mongo-db.test.ts` (+55 -1) 📝 `packages/mongo-adapter/src/mongodb-adapter.ts` (+7 -1) </details> ### 📄 Description https://github.com/better-auth/better-auth/issues/7892 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes Mongo adapter updates to keep id and FK fields as ObjectId and avoid generating new ids during update. Prevents string FK values (e.g., session.userId) after updates. - **Bug Fixes** - Apply ObjectId coercion on create and update, preserving existing ObjectId values. - Add an e2e test suite verifying session.userId remains an ObjectId before and after update. <sup>Written for commit 4f983c607d5dc52a43c206c653c2c9874ffd11e0. Summary will update 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 13:44:58 -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#7664