{"id":"5c8f16b261ff6555","repo":"mongodb/node-mongodb-native","slug":"multiple-text-records-not-allowed","errorCode":null,"errorMessage":"Multiple text records not allowed","messagePattern":"Multiple text records not allowed","errorType":"exception","errorClass":"MongoParseError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":117,"sourceCode":"  }\n\n  const hostAddresses = addresses.map(r => HostAddress.fromString(`${r.name}:${r.port ?? 27017}`));\n\n  validateLoadBalancedOptions(hostAddresses, options, true);\n\n  // Use the result of resolving the TXT record and add options from there if they exist.\n  let record;\n  try {\n    record = await txtResolutionPromise;\n  } catch (error) {\n    if (error.code !== 'ENODATA' && error.code !== 'ENOTFOUND') {\n      throw error;\n    }\n    return hostAddresses;\n  }\n\n  if (record.length > 1) {\n    throw new MongoParseError('Multiple text records not allowed');\n  }\n\n  const txtRecordOptions = new URLSearchParams(record[0].join(''));\n  const txtRecordOptionKeys = [...txtRecordOptions.keys()];\n  if (txtRecordOptionKeys.some(key => !VALID_TXT_RECORDS.includes(key))) {\n    throw new MongoParseError(`Text record may only set any of: ${VALID_TXT_RECORDS.join(', ')}`);\n  }\n\n  if (VALID_TXT_RECORDS.some(option => txtRecordOptions.get(option) === '')) {\n    throw new MongoParseError('Cannot have empty URI params in DNS TXT Record');\n  }\n\n  const source = txtRecordOptions.get('authSource') ?? undefined;\n  const replicaSet = txtRecordOptions.get('replicaSet') ?? undefined;\n  const loadBalanced = txtRecordOptions.get('loadBalanced') ?? undefined;\n\n  if (\n    !options.userSpecifiedAuthSource &&","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L99-L135","documentation":"Thrown by resolveSRVRecord() when the DNS TXT record query for the SRV hostname returns more than one TXT record. The mongodb+srv:// scheme permits at most one TXT record to carry additional default options (authSource, replicaSet, loadBalanced). Multiple TXT records are ambiguous and rejected as a MongoParseError after the lookup completes.","triggerScenarios":"A hostname that has two or more TXT records configured at the same name; a DNS provider that splits long option strings into multiple records; misconfiguration during cluster migration leaving stale TXT records alongside new ones.","commonSituations":"DNS admin added a second TXT record for a different purpose on the same name; using the same subdomain for both MongoDB options and an unrelated verification record (SPF/DKIM-like); migration between auth models leaving an old TXT behind.","solutions":["Query TXT records: dig <host> TXT or nslookup -type=txt <host> and confirm how many exist.","Consolidate all options into a single TXT record, e.g. \"authSource=admin&replicaSet=rs0\".","Remove unrelated TXT records from that hostname or move MongoDB options to a dedicated subdomain.","After DNS changes, flush local resolver cache and retry the connection."],"exampleFix":"// DNS before (two TXT records on same name):\n//   TXT \"authSource=admin\"\n//   TXT \"replicaSet=rs0\"\n// DNS after (one TXT record):\n//   TXT \"authSource=admin&replicaSet=rs0\"","handlingStrategy":"validation","validationCode":"import { promises as dns } from 'dns';\nasync function assertSingleTxt(host: string): Promise<void> {\n  const records = await dns.resolveTxt(host);\n  if (records.length > 1) {\n    throw new Error(`${host} has ${records.length} TXT records; MongoDB permits only one`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await client.connect();\n} catch (e) {\n  if (e instanceof MongoParseError && /Multiple text records not allowed/.test(e.message)) {\n    throw new Error('DNS misconfiguration: consolidate TXT records to one');\n  }\n  throw e;\n}","preventionTips":["Keep exactly one TXT record per SRV hostname.","Avoid placing unrelated verification records on the same name.","Re-query TXT after DNS changes."],"tags":["connection-string","dns","srv","config"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}