UNPKG

@notross/mongo-singleton

Version:

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

33 lines 983 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildConnectionString = buildConnectionString; /** * 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', * }); */ 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