UNPKG

@notross/mongo-singleton

Version:

A lightweight, zero-fuss way to get a single shared MongoDB connection across your Node.js codebase.

30 lines 858 B
/** * Builds a MongoDB connection string from granular connection properties. * * @param props - Full connection properties used to compose the URI. * @returns The formatted MongoDB URI. * @example * const uri = buildConnectionString({ * prefix: 'mongodb://', * username: 'user', * password: 'pass', * host: 'localhost', * port: 27017, * defaultauthdb: 'admin', * }); */ export function buildConnectionString({ prefix, username, password, host, port, defaultauthdb, authSource, options, }) { let uri = `${prefix}${username}:${password}@${host}`; if (port) { uri += `:${port}`; } uri += `/${defaultauthdb}`; if (authSource) { uri += `?authSource=${authSource}`; } if (options) { uri += `&${options.toString()}`; } return uri; } //# sourceMappingURL=connection-string.js.map