mongodb/node-mongodb-native · error · MongoAPIError
Server record does not have at least one more domain level t
Error message
Server record does not have at least one more domain level than parent URI
What it means
Thrown by checkParentDomainMatch() during SRV/TXT-record validation when the srvHost has fewer than three dot-separated parts AND the resolved record's host has the same or fewer parts than the srvHost. The driver requires SRV-returned hosts to live at least one DNS level below the srvHost to prevent a compromised DNS server from redirecting the client to arbitrary hosts. It surfaces as a MongoAPIError and originates from srv_polling.ts and connection_string.ts.
Source
Thrown at src/utils.ts:1181
const allCharacterBeforeFirstDot = /^.*?\./;
const srvIsLessThanThreeParts = normalizedSrvHost.split('.').length < 3;
// Remove all characters before first dot
// Add leading dot back to string so
// an srvHostDomain = '.trusted.site'
// will not satisfy an addressDomain that endsWith '.fake-trusted.site'
const addressDomain = `.${normalizedAddress.replace(allCharacterBeforeFirstDot, '')}`;
let srvHostDomain = srvIsLessThanThreeParts
? normalizedSrvHost
: `.${normalizedSrvHost.replace(allCharacterBeforeFirstDot, '')}`;
if (!srvHostDomain.startsWith('.')) {
srvHostDomain = '.' + srvHostDomain;
}
if (
srvIsLessThanThreeParts &&
normalizedAddress.split('.').length <= normalizedSrvHost.split('.').length
) {
throw new MongoAPIError(
'Server record does not have at least one more domain level than parent URI'
);
}
if (!addressDomain.endsWith(srvHostDomain)) {
throw new MongoAPIError('Server record does not share hostname with parent URI');
}
}
/**
* Perform a get request that returns status and body.
* @internal
*/
export function get(
url: URL | string,
options: http.RequestOptions = {}
): Promise<{ body: string; status: number | undefined }> {
return new Promise((resolve, reject) => {
/* eslint-disable prefer-const */View on GitHub (pinned to 3366c21a63)
Solutions
- Use a srvHost with at least three labels (e.g. _mongodb._tcp.cluster.example.com) so children can be one level deeper.
- Ensure every SRV target hostname is a proper subdomain of the srvHost.
- If SRV is not required, switch to a standard mongodb:// seedlist connection string, which bypasses SRV hostname validation.
- Work with your DNS/Atlas administrator to correct the published SRV records.
Example fix
// before const uri = 'mongodb+srv://db.srv/'; // two-label srvHost; SRV child not deeper => MongoAPIError // after const uri = 'mongodb+srv://cluster0.example.com/'; // three-label srvHost with valid child targets
Defensive patterns
Strategy: try-catch
Try / catch
try {
await client.connect();
} catch (err) {
if (err instanceof MongoAPIError && /does not have at least one more domain level/.test(err.message)) {
throw new Error('srvHost must have >=3 labels and SRV targets must be deeper subdomains', { cause: err });
}
throw err;
} Prevention
- Use a three-or-more-label srvHost for mongodb+srv:// connections.
- Verify SRV targets with `dig SRV _mongodb._tcp.<srvHost>` before deploying.
- Prefer the Atlas-generated connection string, which satisfies the rules by construction.
When it happens
Trigger: Using `mongodb+srv://short.srv/` where short.srv has < 3 labels (e.g. a two-label host) and the SRV record returns a host that does not add a subdomain level. Also from TXT record hostname checks during initial connection-string resolution.
Common situations: Misconfigured Atlas/seedlist SRV records; using mongodb+srv:// with a custom short hostname that violates the cross-driver SRV rules; a private DNS setup where SRV target hostnames are siblings of (rather than children of) the srvHost.
Related errors
- Server record does not share hostname with parent URI
- Option "srvHost" must not be empty
- No addresses found at host
- Multiple text records not allowed
- Text record may only set any of: ${VALID_TXT_RECORDS.join(',
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/c32caa5592db0cad.json.
Report an issue: GitHub.