mongodb/node-mongodb-native · error · MongoAPIError

No addresses found at host

Error message

No addresses found at host

What it means

Thrown by resolveSRVRecord() after a successful DNS SRV query that returned zero records for _<srvServiceName>._tcp.<srvHost>. The mongodb+srv:// scheme requires the hostname to publish at least one SRV record pointing to mongod/mongos hosts. It is a MongoAPIError raised after the DNS round-trip succeeds but yields nothing.

Source

Thrown at src/connection_string.ts:94

 */
export async function resolveSRVRecord(options: MongoOptions): Promise<HostAddress[]> {
  if (typeof options.srvHost !== 'string') {
    throw new MongoAPIError('Option "srvHost" must not be empty');
  }

  // Asynchronously start TXT resolution so that we do not have to wait until
  // the SRV record is resolved before starting a second DNS query.
  const lookupAddress = options.srvHost;
  const txtResolutionPromise = resolveTxt(lookupAddress);

  txtResolutionPromise.then(undefined, squashError); // rejections will be handled later

  const hostname = `_${options.srvServiceName}._tcp.${lookupAddress}`;
  // Resolve the SRV record and use the result as the list of hosts to connect to.
  const addresses = await resolveSrv(hostname);

  if (addresses.length === 0) {
    throw new MongoAPIError('No addresses found at host');
  }

  for (const { name } of addresses) {
    checkParentDomainMatch(name, lookupAddress);
  }

  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;
    }

View on GitHub (pinned to 3366c21a63)

Solutions

  1. Verify the SRV record exists: dig _mongodb._tcp.<host> SRV or nslookup -type=srv _mongodb._tcp.<host>.
  2. If the cluster does not publish SRV records, switch to a standard mongodb:// URI listing hosts directly.
  3. Confirm srvServiceName (if overridden) matches the service name configured in DNS.
  4. Check with your DNS/cluster admin that records were created and propagated.

Example fix

// before
const uri = 'mongodb+srv://mycluster.selfhosted.example/db'; // no SRV record
// after
const uri = 'mongodb://host1:27017,host2:27017,host3:27017/db?replicaSet=mycluster';
Defensive patterns

Strategy: validation

Validate before calling

import { promises as dns } from 'dns';
async function hasSrvRecord(host: string, service = 'mongodb'): Promise<boolean> {
  try {
    const records = await dns.resolveSrv(`_${service}._tcp.${host}`);
    return records.length > 0;
  } catch {
    return false;
  }
}
// gate before connect for mongodb+srv URIs

Try / catch

try {
  await client.connect();
} catch (e) {
  if (e instanceof MongoAPIError && /No addresses found at host/.test(e.message)) {
    // fall back to a standard host list URI, or alert ops
  }
  throw e;
}

Prevention

When it happens

Trigger: Using a mongodb+srv:// URI whose hostname has no SRV record configured (e.g. a bare hostname or a non-Atlas host without SRV); srvServiceName customized to a value with no matching record; hostname is a CNAME to a host that lacks SRV records; recently deleted DNS records during cluster migration.

Common situations: Connecting with Atlas-style URI to a self-managed cluster that uses standard mongodb:// host lists; DNS provider outage returning empty NXDOMAIN-like result; typo in the cluster subdomain; using srvServiceName for a load-balanced topology incorrectly.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04). Data as JSON: /data/errors/3f4d9431bbbb4db2.json. Report an issue: GitHub.