mongodb adapter should supportJSON #2749

Open
opened 2026-03-13 10:17:44 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @DibyodyutiMondal on GitHub (Jan 22, 2026).

Is this suited for github?

  • Yes, this is suited for github

Mongodb supports json, but adding custom json fields to the schema, causes the fields to be stored as JSON strings in the database.

Describe the solution you'd like

0e4efdeeb2/packages/mongo-adapter/src/mongodb-adapter.ts (L574-L575)

In general, this piece of code should be approached again and ensure that the options are the best possible
It would be better if the options can be overriden by the user when required.

Describe alternatives you've considered

Additional context

Originally created by @DibyodyutiMondal on GitHub (Jan 22, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Mongodb supports json, but adding custom json fields to the schema, causes the fields to be stored as JSON strings in the database. ### Describe the solution you'd like https://github.com/better-auth/better-auth/blob/0e4efdeeb21694e30714ab9b8c6da6c720809e20/packages/mongo-adapter/src/mongodb-adapter.ts#L574-L575 In general, this piece of code should be approached again and ensure that the options are the best possible It would be better if the options can be overriden by the user when required. ### Describe alternatives you've considered - ### Additional context -
GiteaMirror added the adapter label 2026-03-13 10:17:44 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 22, 2026):

It looks like there is an open issue discussing the need for enhanced support for custom JSON fields within the MongoDB adapter. Specifically, when you add custom JSON fields to the schema, these fields are stored as JSON strings in the database. The suggestion is to allow these options to be overridden by users, to ensure better functionality and customization [1], [3].

For now, if you would like to discuss further or if you have specific questions regarding this, please feel free to tag @better-auth-agent so I can assist you better!

Are there specific features or enhancements you're looking for in the MongoDB adapter?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Jan 22, 2026): It looks like there is an open issue discussing the need for enhanced support for custom JSON fields within the MongoDB adapter. Specifically, when you add custom JSON fields to the schema, these fields are stored as JSON strings in the database. The suggestion is to allow these options to be overridden by users, to ensure better functionality and customization [[1]](https://www.better-auth.com/docs/adapters/mongo), [[3]](https://github.com/better-auth/better-auth/issues/5387). For now, if you would like to discuss further or if you have specific questions regarding this, please feel free to tag @better-auth-agent so I can assist you better! Are there specific features or enhancements you're looking for in the MongoDB adapter? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@DibyodyutiMondal commented on GitHub (Jan 22, 2026):

@better-auth-agent, which open issue are you referring to?

@DibyodyutiMondal commented on GitHub (Jan 22, 2026): @better-auth-agent, which open issue are you referring to?
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 22, 2026):

The MongoDB adapter in Better Auth currently does not support custom JSON fields directly. There is an open issue indicating that this feature would allow custom JSON fields to be managed more effectively, preventing them from being stored as strings in the database. The suggestion is to revisit certain pieces of code to ensure optimal configuration options for users [1].

If you're interested in contributing to this enhancement or have specific thoughts on how custom JSON field support should work, it would be great to hear your ideas! Are you currently facing any challenges while using the MongoDB adapter?

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Jan 22, 2026): The MongoDB adapter in Better Auth currently does not support custom JSON fields directly. There is an open issue indicating that this feature would allow custom JSON fields to be managed more effectively, preventing them from being stored as strings in the database. The suggestion is to revisit certain pieces of code to ensure optimal configuration options for users [[1]](https://www.better-auth.com/docs/adapters/mongo). If you're interested in contributing to this enhancement or have specific thoughts on how custom JSON field support should work, it would be great to hear your ideas! Are you currently facing any challenges while using the MongoDB adapter? <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@DibyodyutiMondal commented on GitHub (Jan 22, 2026):

@better-auth-agent, I do not see the issue regarding JSON fields in your citations, but I do see the issue regarding custom Id generation.

While they are not the same issue - they do stem from a common source - mongodb adapter config is not customizable/configurable from the outside

@DibyodyutiMondal commented on GitHub (Jan 22, 2026): @better-auth-agent, I do not see the issue regarding JSON fields in your citations, but I do see the issue regarding custom Id generation. While they are not the same issue - they do stem from a common source - mongodb adapter config is not customizable/configurable from the outside
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 22, 2026):

It seems you're referring to the MongoDB adapter and the challenge with handling JSON fields in your schema. This is indeed a topic of importance since adding custom JSON fields can lead to them being stored as strings in the database, which can create issues when querying later.

Currently, there appears to be ongoing conversation about making the options within the MongoDB adapter more customizable, which is aligned with your concern about configuration flexibility. While I do not have a specific resolution for your issue regarding JSON fields, it would be beneficial for the Better Auth team, particularly @bekacru and @ping__, to look into this matter as well.

If you'd like support in navigating this or have additional context or questions, don't hesitate to ask! What kind of solutions or features do you think would be most beneficial for handling JSON in your configurations?

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Jan 22, 2026): It seems you're referring to the MongoDB adapter and the challenge with handling JSON fields in your schema. This is indeed a topic of importance since adding custom JSON fields can lead to them being stored as strings in the database, which can create issues when querying later. Currently, there appears to be ongoing conversation about making the options within the MongoDB adapter more customizable, which is aligned with your concern about configuration flexibility. While I do not have a specific resolution for your issue regarding JSON fields, it would be beneficial for the Better Auth team, particularly @bekacru and @ping__, to look into this matter as well. If you'd like support in navigating this or have additional context or questions, don't hesitate to ask! What kind of solutions or features do you think would be most beneficial for handling JSON in your configurations? <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2749