[PR #5988] Use "user id" as _id in mongo adapter if defined when creating user #14612

Closed
opened 2026-04-13 09:32:31 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5988

State: closed
Merged: No


IMO when you define a user id when using the MongoAdapter, then the id of user user should be the same on the user object that is created. To achieve this the _id field has to be the same, see https://www.mongodb.com/docs/drivers/node/current/crud/insert/#a-note-about-_id


Summary by cubic

Use the provided user id as the MongoDB _id when creating a user. Falls back to the insertedId if no id is provided, keeping user ids consistent across the app and database.

Written for commit bbc37f1444. Summary will update automatically on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5988 **State:** closed **Merged:** No --- IMO when you define a user id when using the MongoAdapter, then the id of user user should be the same on the user object that is created. To achieve this the _id field has to be the same, see https://www.mongodb.com/docs/drivers/node/current/crud/insert/#a-note-about-_id <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Use the provided user id as the MongoDB _id when creating a user. Falls back to the insertedId if no id is provided, keeping user ids consistent across the app and database. <sup>Written for commit bbc37f14442eb8387f4a1fb772f3cd4c24f4d84d. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 09:32:31 -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#14612