Skip to content

fix(MongoClient): use mongodb-connection-string-url for host parsing (#58)#61

Open
Botik wants to merge 1 commit intodoubleloop-io:mainfrom
Botik:fix/58-mongoclient-url-parsing
Open

fix(MongoClient): use mongodb-connection-string-url for host parsing (#58)#61
Botik wants to merge 1 commit intodoubleloop-io:mainfrom
Botik:fix/58-mongoclient-url-parsing

Conversation

@Botik
Copy link
Copy Markdown

@Botik Botik commented Apr 3, 2026

Summary

fix(MongoClient): use mongodb-connection-string-url for host parsing

  • Replace new URL(url).host with ConnectionString from mongodb-connection-string-url for proper MongoDB connection string parsing
  • Support multi-host connection strings (e.g., mongodb://host1:27017,host2:27017)
  • Handle SRV and invalid URLs gracefully

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 3, 2026

🦋 Changeset detected

Latest commit: a0e9a59

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
effect-mongodb Patch
@effect-mongodb/services Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Collaborator

@devmatteini devmatteini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Botik and thank you for your contribution!

I've added some comments about the changes

"effect-mongodb": patch
---

fix(MongoClient): update tests for ConnectionString host parsing (#58)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be "Fix MongoClient.connect connection string parsing for error reporting"

import type { DbOptions, MongoClientOptions } from "mongodb"
import type { DbOptions, MongoClientOptions, MongoParseError } from "mongodb"
import { MongoClient as MongoClient_ } from "mongodb"
import { ConnectionString } from "mongodb-connection-string-url"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid installing another dependency just for error reporting.
This would be a breaking change for every user of the library, which is not ideal.

I would like to find other ways to parse the connection string, maybe there is something built-in in mongodb package? Or otherwise we can also consider an empty array for hosts as you always have the cause error in the MongoError.cause

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.

new URL() in error handling fails on valid MongoDB connection strings with multiple hosts

2 participants