{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L99-L135","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect TXT records: dig TXT <srvHost> (or nslookup -type=TXT <srvHost>).","Remove all but the single intended MongoDB TXT record from DNS.","Ensure the remaining TXT record contains the valid options (authSource, replicaSet, loadBalanced)."],"exampleFix":"// DNS before:\n//   @  IN  TXT \"authSource=admin\"\n//   @  IN  TXT \"replicaSet=rs0\"\n// DNS after (combine into one):\n//   @  IN  TXT \"authSource=admin&replicaSet=rs0\"","handlingStrategy":"validation","validationCode":"import { promises as dns } from 'dns';\n\nasync function assertSingleTxt(srvHost: string) {\n  const records = await dns.resolveTxt(srvHost);\n  if (records.length > 1) {\n    throw new Error(`Expected 1 TXT record at ${srvHost}, got ${records.length}`);\n  }\n  return records[0];\n}","typeGuard":null,"tryCatchPattern":"try {\n  await client.connect();\n} catch (err) {\n  if (err instanceof MongoParseError && /Multiple text records not allowed/.test(err.message)) {\n    throw new Error('DNS misconfiguration: only one TXT record permitted for SRV host');\n  }\n  throw err;\n}","preventionTips":["Audit DNS TXT records whenever MongoDB options change.","Document the single-TXT rule for ops teams managing the zone."],"tags":["dns","connection-string","srv","txt-record"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}