Skip to content

fix(mongodb): connection strings with several hosts (replica sets) are rejected or throw FormatException #1309

Closed

Description

@ZhuchkaTriplesix

Problem

Uri.tryParse('mongodb://h1:27017,h2:27017/db?replicaSet=rs0') is null (the port segment is 27017,h2:27017), and Uri.parse throws. A host list is valid in the MongoDB URI format and is the normal form for replica sets.

  • New connection from URL (lib/features/connections/connection_url_parser.dart): Invalid URL/URI format.
  • Connector (lib/core/database/mongodb_connection.dart:92, 122, 188, 303): Uri.parse on the saved string throws FormatException in buildConnectionUri (SSH host override) and buildUriForDatabase (opening another database from the tree), so a replica-set connection saved through the form fails there.
  • With a mongodb+srv:// string and an SSH tunnel, replace(host: ..., port: ...) produces an SRV URI with a port, which is invalid.

Scope

  • A small URI splitter for the MongoDB scheme that keeps the host list as is (scheme, userinfo, hosts, path, query) for building and for the URL parser; no Uri.parse on a host list.
  • With an SSH tunnel, define what to do for several hosts (tunnel the first, or refuse with a clear message) and for +srv (refuse with a clear message).
  • Tests: parse, database switch and tunnel override for a multi-host string.

Acceptance

  • A multi-host URI imports from New connection from URL, and its first host and options are in the row.
  • Opening another database of a replica-set connection works.
  • +srv with a tunnel gives an explanation, not FormatException.

Activity

  1. added
    bugSomething isn't working
    parserTheme parser epic label: parser
    connectionsDatabase connections, URI parsing, pools
    P2Medium priority / Parity & Refactoring
    on Oct 10, 2026
  2. added a commit that references this issue on Oct 10, 2026
  3. ZhuchkaTriplesix commented on Oct 10, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Сделано в #1325, смержено в dev.

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

Metadata

Metadata

Labels

P2Medium priority / Parity & RefactoringbugSomething isn't workingconnectionsDatabase connections, URI parsing, poolsparserTheme parser epic label: parser

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions