INNER CODE UNIT · TypeScript

generateConnectionWithDirectHost

aliez-ren/mongood · src/utils/index.ts:3

export function generateConnectionWithDirectHost(
  host: string,
  connection?: string,
): string | undefined {
  if (!connection) {
    return undefined
  }
  try {
    const parsed = mongodbUri.parse(connection)
    const [_host, _port] = host.split(':')
    return mongodbUri.format({
      ...parsed,
      scheme: 'mongodb',
      hosts: [{ host: _host, port: parseInt(_port, 10) }],
      options: {
        ...parsed?.options,
        connect: 'direct',
      },

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…