mongodb/node-mongodb-native · error · MongoParseError

Cannot have empty URI params in DNS TXT Record

Error message

Cannot have empty URI params in DNS TXT Record

What it means

Each allowed TXT record option must have a value. The driver iterates VALID_TXT_RECORDS and rejects any option whose value is the empty string, because an optionless key in a TXT record is ambiguous and almost always a DNS formatting mistake.

Solutions

  1. Inspect the TXT record: dig TXT <srvHost>.
  2. Either supply a value for the empty key or remove the key entirely.
  3. Reload the connection after DNS TTL expires or flush local DNS cache.

Example fix

// DNS TXT before: "authSource=admin&loadBalanced="
// DNS TXT after:   "authSource=admin&loadBalanced=true"
Defensive patterns

Strategy: validation

Validate before calling

import { promises as dns } from 'dns';

async function validateTxtValues(srvHost: string) {
  const records = await dns.resolveTxt(srvHost);
  if (!records.length) return;
  const params = new URLSearchParams(records[0].join(''));
  for (const [k, v] of params.entries()) {
    if (v === '') throw new Error(`TXT option '${k}' has empty value`);
  }
}

Prevention

When it happens

Trigger: A DNS TXT record containing a trailing 'authSource=' with no value, e.g. 'authSource=admin&replicaSet=' or 'authSource='. Produced while parsing TXT record options in resolveSRVRecord.

Common situations: Operator deletes a TXT value but leaves the key, or copy-pastes a malformed TXT string into the DNS management UI.

Related errors


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

Appendix: source

Thrown at src/connection_string.ts:127

  } 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 &&
    source &&
    options.credentials &&
    !AUTH_MECHS_AUTH_SRC_EXTERNAL.has(options.credentials.mechanism)
  ) {
    options.credentials = MongoCredentials.merge(options.credentials, { source });
  }

  if (!options.userSpecifiedReplicaSet && replicaSet) {
    options.replicaSet = replicaSet;
  }

View on GitHub (pinned to dce7939f86)