mongodb/node-mongodb-native · error · MongoParseError

Multiple text records not allowed

Error message

Multiple text records not allowed

What it means

DNS TXT records are used by mongodb+srv:// to carry default connection options (authSource, replicaSet, loadBalanced). The MongoDB SRV spec mandates at most one TXT record. If DNS returns more than one TXT record for the SRV host, the driver refuses to pick ambiguously and throws.

Solutions

  1. Inspect TXT records: dig TXT <srvHost> (or nslookup -type=TXT <srvHost>).
  2. Remove all but the single intended MongoDB TXT record from DNS.
  3. Ensure the remaining TXT record contains the valid options (authSource, replicaSet, loadBalanced).

Example fix

// DNS before:
//   @  IN  TXT "authSource=admin"
//   @  IN  TXT "replicaSet=rs0"
// DNS after (combine into one):
//   @  IN  TXT "authSource=admin&replicaSet=rs0"
Defensive patterns

Strategy: validation

Validate before calling

import { promises as dns } from 'dns';

async function assertSingleTxt(srvHost: string) {
  const records = await dns.resolveTxt(srvHost);
  if (records.length > 1) {
    throw new Error(`Expected 1 TXT record at ${srvHost}, got ${records.length}`);
  }
  return records[0];
}

Try / catch

try {
  await client.connect();
} catch (err) {
  if (err instanceof MongoParseError && /Multiple text records not allowed/.test(err.message)) {
    throw new Error('DNS misconfiguration: only one TXT record permitted for SRV host');
  }
  throw err;
}

Prevention

When it happens

Trigger: A mongodb+srv:// connection whose DNS zone advertises two or more TXT records at the SRV hostname. Encountered after the SRV lookup succeeds, during TXT record processing in resolveSRVRecord.

Common situations: Misconfigured DNS where an admin added a second TXT record (often a leftover SPF-like or legacy record) alongside the intended MongoDB TXT record, or split-brain DNS publishing different TXT sets.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11). Data as JSON: /api/errors/5c8f16b261ff6555. Report an issue: GitHub.

Appendix: source

Thrown at src/connection_string.ts:117

  }

  const hostAddresses = addresses.map(r => HostAddress.fromString(`${r.name}:${r.port ?? 27017}`));

  validateLoadBalancedOptions(hostAddresses, options, true);

  // Use the result of resolving the TXT record and add options from there if they exist.
  let record;
  try {
    record = await txtResolutionPromise;
  } catch (error) {
    if (error.code !== 'ENODATA' && error.code !== 'ENOTFOUND') {
      throw error;
    }
    return hostAddresses;
  }

  if (record.length > 1) {
    throw new MongoParseError('Multiple text records not allowed');
  }

  const txtRecordOptions = new URLSearchParams(record[0].join(''));
  const txtRecordOptionKeys = [...txtRecordOptions.keys()];
  if (txtRecordOptionKeys.some(key => !VALID_TXT_RECORDS.includes(key))) {
    throw new MongoParseError(`Text record may only set any of: ${VALID_TXT_RECORDS.join(', ')}`);
  }

  if (VALID_TXT_RECORDS.some(option => txtRecordOptions.get(option) === '')) {
    throw new MongoParseError('Cannot have empty URI params in DNS TXT Record');
  }

  const source = txtRecordOptions.get('authSource') ?? undefined;
  const replicaSet = txtRecordOptions.get('replicaSet') ?? undefined;
  const loadBalanced = txtRecordOptions.get('loadBalanced') ?? undefined;

  if (
    !options.userSpecifiedAuthSource &&

View on GitHub (pinned to dce7939f86)