mongodb/node-mongodb-native · error · MongoParseError
Multiple text records not allowed
Error message
Multiple text records not allowed
What it means
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.
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 3366c21a63)
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.
Example fix
// DNS before (two TXT records on same name): // TXT "authSource=admin" // TXT "replicaSet=rs0" // DNS after (one TXT record): // TXT "authSource=admin&replicaSet=rs0"
Defensive patterns
Strategy: validation
Validate before calling
import { promises as dns } from 'dns';
async function assertSingleTxt(host: string): Promise<void> {
const records = await dns.resolveTxt(host);
if (records.length > 1) {
throw new Error(`${host} has ${records.length} TXT records; MongoDB permits only one`);
}
} Try / catch
try {
await client.connect();
} catch (e) {
if (e instanceof MongoParseError && /Multiple text records not allowed/.test(e.message)) {
throw new Error('DNS misconfiguration: consolidate TXT records to one');
}
throw e;
} Prevention
- Keep exactly one TXT record per SRV hostname.
- Avoid placing unrelated verification records on the same name.
- Re-query TXT after DNS changes.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Option "srvHost" must not be empty
- Text record may only set any of: ${VALID_TXT_RECORDS.join(',
- Cannot have empty URI params in DNS TXT Record
- No addresses found at host
- Cannot combine replicaSet option with srvMaxHosts
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/5c8f16b261ff6555.json.
Report an issue: GitHub.