[GH-ISSUE #7213] JSDoc for Mongo DB Adapter is wrong #10760

Closed
opened 2026-04-13 07:05:55 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @fdx-spencer-porteous on GitHub (Jan 9, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7213

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Use the mongo db adapter, providing a mongo client for the client property in the db config.

If your mongo instance doesn't support transactions this will fail despite the docs saying that transactions are disabled by default.

Current vs. Expected behavior

Image Here it says that transaction defaults to false, but in the actual code it defaults to true if client is provided.

This caused an outage for us as it previously did default to false.

Image

What version of Better Auth are you using?

1.4.7

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:07:05 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6020",
    "release": "25.2.0",
    "cpuCount": 10,
    "cpuModel": "Apple M2 Pro",
    "totalMemory": "32.00 GB",
    "freeMemory": "0.09 GB"
  },
  "node": {
    "version": "v20.18.3",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

N/A

Additional context

N/A

Originally created by @fdx-spencer-porteous on GitHub (Jan 9, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7213 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Use the mongo db adapter, providing a mongo client for the client property in the db config. If your mongo instance doesn't support transactions this will fail despite the docs saying that transactions are disabled by default. ### Current vs. Expected behavior <img width="1135" height="605" alt="Image" src="https://github.com/user-attachments/assets/8cff086e-f7ed-4648-a27c-39761067c154" /> Here it says that transaction defaults to false, but in the actual code it defaults to true if client is provided. This caused an outage for us as it previously did default to false. <img width="1136" height="493" alt="Image" src="https://github.com/user-attachments/assets/25dbbab5-0e17-4720-b7c8-ce5e1117e258" /> ### What version of Better Auth are you using? 1.4.7 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:07:05 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6020", "release": "25.2.0", "cpuCount": 10, "cpuModel": "Apple M2 Pro", "totalMemory": "32.00 GB", "freeMemory": "0.09 GB" }, "node": { "version": "v20.18.3", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript N/A ``` ### Additional context N/A
GiteaMirror added the locked label 2026-04-13 07:05:55 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 9, 2026):

You're right—the JSDoc for the MongoDB adapter's transaction option was incorrect in Better Auth v1.4.7. The docs said transactions default to false, but the actual code enables transactions by default if you provide a Mongo client, unless you explicitly set transaction: false. This mismatch caused issues for users whose MongoDB doesn't support transactions, like yours, and led to unexpected failures when upgrading or relying on the documented default.

This behavior was confirmed in the code and later clarified in the documentation: for MongoDB, transactions now default to on (true) when a client is provided, unless you disable them yourself. Other adapters like Drizzle, Kysely, and Prisma still default to false. See the PR that fixed the docs and the code logic.

If your MongoDB doesn't support transactions, set transaction: false in your adapter config to avoid these errors. After upgrading, always double-check your adapter config and the latest docs to avoid surprises from changes like this.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3726783235 --> @dosubot[bot] commented on GitHub (Jan 9, 2026): <!-- Answer --> You're right—the JSDoc for the MongoDB adapter's transaction option was incorrect in Better Auth v1.4.7. The docs said transactions default to false, but the actual code enables transactions by default if you provide a Mongo client, unless you explicitly set transaction: false. This mismatch caused issues for users whose MongoDB doesn't support transactions, like yours, and led to unexpected failures when upgrading or relying on the documented default. This behavior was confirmed in the code and later clarified in the documentation: for MongoDB, transactions now default to on (true) when a client is provided, unless you disable them yourself. Other adapters like Drizzle, Kysely, and Prisma still default to false. See the [PR that fixed the docs](https://github.com/better-auth/better-auth/pull/5223) and [the code logic](https://github.com/better-auth/better-auth/blob/c31c92f3d24f3ccfb6776d4634e0681c6dee2db5/packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts#L31-L593). If your MongoDB doesn't support transactions, set transaction: false in your adapter config to avoid these errors. After upgrading, always double-check your adapter config and the latest docs to avoid surprises from changes like this. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/fa1b4d03-4975-4725-9ff3-f696e4490a41?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/fa1b4d03-4975-4725-9ff3-f696e4490a41?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/fa1b4d03-4975-4725-9ff3-f696e4490a41?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/fa1b4d03-4975-4725-9ff3-f696e4490a41?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/fa1b4d03-4975-4725-9ff3-f696e4490a41?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/fa1b4d03-4975-4725-9ff3-f696e4490a41?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/fa1b4d03-4975-4725-9ff3-f696e4490a41?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=You%27re%20right%E2%80%94the%20JSDoc%20for%20the%20MongoDB%20adapter%27s%20transaction%20option%20was%20incorrect%20in%20Better%20Auth%20v1.4.7.%20The%20docs%20said%20transactions%20default%20to%20false%2C%20but%20the%20actual%20code%20enables%20transactions%20by%20default%20if%20you%20provide%20a%20Mongo%20client%2C%20unless%20you%20explicitly%20set%20transaction%3A%20false.%20This%20mismatch%20caused%20issues%20for%20users%20whose%20MongoDB%20doesn%27t%20support%20transactions%2C%20like%20yours%2C%20and%20led%20to%20unexpected%20failures%20when%20upgrading%20or%20relying%20on%20the%20documented%20default.%0A%0AThis%20behavior%20was%20confirmed%20in%20the%20code%20and%20later%20clarified%20in%20the%20documentation%3A%20for%20MongoDB%2C%20transactions%20now%20default%20to%20on%20%28true%29%20when%20a%20client%20is%20provided%2C%20unless%20you%20disable%20them%20yourself.%20Other%20adapters%20like%20Drizzle%2C%20Kysely%2C%20and%20Prisma%20still%20default%20to%20false.%20See%20the%20%5BPR%20that%20fixed%20the%20docs%5D%28https%3A//github.com/better-auth/better-auth/pull/5223%29%20and%20%5Bthe%20code%20logic%5D%28https%3A//github.com/better-auth/better-auth/blob/c31c92f3d24f3ccfb6776d4634e0681c6dee2db5/packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts%23L31-L593%29.%0A%0AIf%20your%20MongoDB%20doesn%27t%20support%20transactions%2C%20set%20transaction%3A%20false%20in%20your%20adapter%20config%20to%20avoid%20these%20errors.%20After%20upgrading%2C%20always%20double-check%20your%20adapter%20config%20and%20the%20latest%20docs%20to%20avoid%20surprises%20from%20changes%20like%20this.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/7213)
Author
Owner

@bytaesu commented on GitHub (Jan 9, 2026):

This seems reasonable because the default behavior is different from other adapters. However, changing the default value could be a breaking change, so it would be better to document it.

@ping-maxwell could you check this?

<!-- gh-comment-id:3727574770 --> @bytaesu commented on GitHub (Jan 9, 2026): This seems reasonable because the default behavior is different from other adapters. However, changing the default value could be a breaking change, so it would be better to document it. @ping-maxwell could you check this?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10760