Skip to content

fix(mongo): accept multi-host connection strings - #30354

Open
lazerg wants to merge 2 commits into
prisma:mainfrom
lazerg:fix/issue-30353-mongo-multi-host-url
Open

lazerg wants to merge 2 commits into
prisma:mainfrom
lazerg:fix/issue-30353-mongo-multi-host-url

Conversation

@lazerg

@lazerg lazerg commented Sep 20, 2026

Copy link
Copy Markdown

Linked issue

Fixes #30353

Summary

The Mongo runtime validates a connection URL with new URL, which cannot parse a seed list. Given mongodb://host1:27017,host2:27017/db it reads 27017,host2:27017 as the port and throws, so every replica-set URI with more than one host was rejected as Mongo URL must be a valid URL before the driver ever saw it. Validation now drops the extra hosts before parsing. Only the scheme and the database path are read off the parsed URL, and the driver still receives the original string.

Testing performed

  • pnpm --dir packages/3-extensions/mongo test — 128 passed. The seed-list test reproduces the report through mongo({ contract, url }) and fails on main with the reported error.
  • pnpm typecheck and pnpm lint — clean.
  • pnpm test:packages — 17300 passed. Three tarball suites fail, but they fail the same way on an unmodified main: their scratch pnpm install cannot resolve dependencies here.
  • Mongo integration suites (test/mongo, test/mongo-runtime) — 145 passed across 17 files.

Skill update

n/a — no CLI flag, public API, config field, or error code changes. A connection string the MongoDB driver already accepts simply stops being rejected.

Checklist

  • All commits are signed off (git commit -s) per the DCO.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated.
  • The PR title is in TML-NNNN: <sentence-case title> form — no Linear ticket, this comes from the issue tracker.
  • The Skill update section above is filled in.

Notes for the reviewer

The scan for the host list starts after the last @ in the authority, because a password is allowed to contain an unencoded comma. Tests cover that case along with a bracketed IPv6 seed list and a seed list with no database path, which still raises the existing "must include a database name" error.

mongodb+srv:// is unaffected: an SRV URI carries one host and no port, so there is no host list to collapse.

Worth noting separately: packages/3-extensions/postgres/src/runtime/binding.ts validates the same way and libpq also accepts multi-host strings, so it likely has the same gap. I left it alone to keep this scoped to the reported issue.

Summary by CodeRabbit

  • Bug Fixes

    • Improved MongoDB connection URL handling for seed lists with bracketed IPv6 addresses.
    • Preserved commas in passwords instead of incorrectly treating them as host separators.
    • Maintained correct database name parsing from connection URLs.
    • Added validation for seed list URLs that do not include a database name.
  • Tests

    • Added coverage for IPv6 seed lists, comma-containing passwords, and missing database names.

Signed-off-by: lazerg <lazerg2@gmail.com>
@lazerg
lazerg requested a review from a team as a code owner September 20, 2026 07:27
@coderabbitai

coderabbitai Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: prisma/orm/.coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: c41526b8-30de-4a49-9d93-910635e91377

📥 Commits

Reviewing files that changed from the base of the PR and between 1890b45 and 18fb865.

📒 Files selected for processing (2)
  • packages/3-extensions/mongo/src/runtime/binding.ts
  • packages/3-extensions/mongo/test/mongo.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The MongoDB runtime now parses multi-host seed-list URLs for validation while preserving the original URL for the driver. Tests cover credentials, IPv6 hosts, commas in passwords, database parsing, and missing database names.

Changes

MongoDB seed-list support

Layer / File(s) Summary
Seed-list URL validation
packages/3-extensions/mongo/src/runtime/binding.ts
Replaces regex-based seed-list collapsing with authority parsing. The logic ignores commas in userinfo, supports bracketed IPv6 hosts, and preserves URLs without a seed-list separator.
Multi-host connection tests
packages/3-extensions/mongo/test/mongo.test.ts
Adds tests for unchanged driver URLs, parsed database names, bracketed IPv6 seed lists, commas in passwords, and missing database names.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: wmadden-electric

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy the coding requirements in #30353. collapseSeedList removes extra hosts only for URL parsing and preserves the original URL for driverFromConnection. It handles credentials, po…
Out of Scope Changes check ✅ Passed The production change and the added MongoDB facade tests directly support #30353. The tests cover edge cases for the same seed-list parsing behavior. No unrelated changes are identified in the reviewe…
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: accepting MongoDB multi-host connection strings.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: lazerg <lazerg2@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MongoDB multi-host connection strings are rejected as invalid URLs

1 participant