mongo-uri-builder is a zero-dependency Node.js module that creates MongoDB connection strings (URIs) from a JavaScript configuration object. Version 4.0.0 is the latest stable release as of 2023. The package is maintained on GitHub with an active issue tracker. It abstracts tedious URI construction, handling hosts, ports, replicas, authentication, and query options. Unlike manual string concatenation, it enforces correct URI encoding and structure. Requires Node.js >=12.
npm install mongo-uri-builderNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a MongoDB connection string with authentication, host, port, database, and query options.
Use import mongoUriBuilder from 'mongo-uri-builder' for default, or import { build } from 'mongo-uri-builder' for named.Replace 'user' with 'username' in the configuration object.
Always specify port explicitly if connecting to non-default port or to ensure default port is used.
Ensure option values do not contain '&' or '='. For complex values, consider manual encoding.
Maintain consistent order in replicas array across environments to avoid connection string differences.
Use const mongoUriBuilder = require('mongo-uri-builder') or import mongoUriBuilder from 'mongo-uri-builder'Replace 'user' with 'username' in the configuration.
Add 'database' property, even if empty string, or provide a database name.
Ensure each replica object has a 'host' property.
Encode or remove special characters from option values.
No dependency data recorded yet.