MCPcopy
hub / github.com/mongodb/node-mongodb-native / url

Method url

test/tools/runner/config.ts:333–443  ·  view source on GitHub ↗

* Construct a connection URL using nodejs's whatwg URL similar to how connection_string.ts * works * * @param options - overrides and settings for URI generation

(
    options?: UrlOptions & {
      useMultipleMongoses?: boolean;
      db?: string;
      replicaSet?: string;
      proxyURIParams?: ProxyParams;
      username?: string;
      password?: string;
      auth?: {
        username?: string;
        password?: string;
      };
      authSource?: string;
      authMechanism?: string;
      authMechanismProperties?: Record<string, any>;
    }
  )

Source from the content-addressed store, hash-verified

331 * @param options - overrides and settings for URI generation
332 */
333 url(
334 options?: UrlOptions & {
335 useMultipleMongoses?: boolean;
336 db?: string;
337 replicaSet?: string;
338 proxyURIParams?: ProxyParams;
339 username?: string;
340 password?: string;
341 auth?: {
342 username?: string;
343 password?: string;
344 };
345 authSource?: string;
346 authMechanism?: string;
347 authMechanismProperties?: Record<string, any>;
348 }
349 ) {
350 options = {
351 db: this.options.db,
352 replicaSet: this.options.replicaSet,
353 proxyURIParams: this.options.proxyURIParams,
354 ...options
355 };
356
357 const FILLER_HOST = 'fillerHost';
358
359 const protocol = 'mongodb';
360 const url = new URL(`${protocol}://${FILLER_HOST}`);
361
362 if (options.replicaSet) {
363 url.searchParams.append('replicaSet', options.replicaSet);
364 }
365
366 if (options.proxyURIParams) {
367 for (const [name, value] of Object.entries(options.proxyURIParams)) {
368 if (value) {
369 url.searchParams.append(name, value);
370 }
371 }
372 }
373
374 url.pathname = `/${options.db}`;
375
376 const username = options.username || this.options.auth?.username;
377 const password = options.password || this.options.auth?.password;
378
379 if (username) {
380 url.username = username;
381 }
382
383 if (password) {
384 url.password = password;
385 }
386
387 if (this.isLoadBalanced) {
388 url.searchParams.append('loadBalanced', 'true');
389 }
390

Calls 4

convertToConnStringMapFunction · 0.85
appendMethod · 0.80
toStringMethod · 0.45
mapMethod · 0.45

Tested by 1

testFunction · 0.36