This package provides a robust API for parsing and manipulating MongoDB connection strings, aligning with the WhatWG URL API specification while introducing MongoDB-specific extensions. It is currently at version 7.0.1 (as of Jan 2026) and is actively maintained by the MongoDB Node.js team. Releases are typically aligned with the major versions of the `mongodb` driver, with rapid iterations within a major version to address issues. Key differentiators from a standard URL object include case-insensitive URL parameters, a `.hosts` property for extracting all host details, an `.isSRV` property to identify `mongodb+srv` schemes, and the immutability of standard `.host`, `.hostname`, `.port`, and `.href` properties, which cannot be directly set and may not return meaningful results in the MongoDB context.
npm install mongodb-connection-string-urlVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing various MongoDB connection string formats, modifying URL parameters, and accessing MongoDB-specific properties like `hosts` and `isSRV`.
Upgrade your Node.js runtime environment to version 20.19.0 or higher.
Access and modify host details exclusively through the MongoDB-specific `.hosts` array property. To modify other URL parts, use methods like `cs.searchParams.set()` or reconstruct the string. The `.href` property is read-only.
Refer to the `mongodb` driver's changelog or documentation to ensure you are using a compatible `mongodb-connection-string-url` version.
If using Node.js modules, ensure your project is configured for ES modules (`"type": "module"` in `package.json`) and use `import ConnectionString from 'mongodb-connection-string-url';`. If you must remain in CommonJS, consider dynamic `import()` or review if an older version of the package or a different MongoDB driver setup is more appropriate.
Ensure `whatwg-url` is resolved to version 14.x or higher in your project's dependency tree. This might require updating `mongodb-connection-string-url` itself, the `mongodb` driver, or using package manager `overrides` or `resolutions` to force the `whatwg-url` version.
Review the MongoDB connection string specification for correct formatting. Ensure all special characters in usernames, passwords, or database names are correctly percent-encoded (e.g., `@` as `%40`, `/` as `%2F`). Verify that the scheme (`mongodb://` or `mongodb+srv://`) and host components are present and correctly formatted.