mongodb/node-mongodb-native · error · MongoAPIError

No addresses found at host

Error message

No addresses found at host

What it means

Thrown when an SRV-based MongoDB+SRV connection string resolves to zero DNS SRV records. The driver performs a DNS SRV lookup on '_<srvServiceName>._tcp.<srvHost>' to discover hosts; if the query succeeds but returns an empty list, the connection cannot proceed. This is distinct from a DNS lookup failure (ENOTFOUND), which surfaces as a DNS error instead.

Solutions

  1. Verify the hostname with: dig SRV _mongodb._tcp.<your-host> (or nslookup -type=SRV _mongodb._tcp.<your-host>) and confirm it returns entries.
  2. Correct the hostname in the mongodb+srv:// URI.
  3. If using a custom service name, ensure srvServiceName matches the published SRV service label, or remove it to use the default 'mongodb'.
  4. If SRV records genuinely should be empty, switch to a standard mongodb:// URI listing hosts explicitly.

Example fix

// before
const c = new MongoClient('mongodb+srv://cluser.example.com/db');
// after
const c = new MongoClient('mongodb+srv://cluster.example.com/db');
Defensive patterns

Strategy: validation

Validate before calling

import { promises as dns } from 'dns';

async function assertSrvResolvable(srvHost: string, srvServiceName = 'mongodb') {
  const name = `_${srvServiceName}._tcp.${srvHost}`;
  const records = await dns.resolveSrv(name);
  if (!records || records.length === 0) {
    throw new Error(`No SRV records found at ${name}`);
  }
  return records;
}

// call before constructing MongoClient for mongodb+srv URIs
await assertSrvResolvable('cluster.example.com');

Type guard

function isSrvUri(uri: string): boolean {
  return /^mongodb\+srv:\/\//i.test(uri);
}

Try / catch

try {
  const client = new MongoClient(srvUri);
  await client.connect();
} catch (err) {
  if (err instanceof MongoAPIError && /No addresses found at host/.test(err.message)) {
    // surface a DNS-config actionable message, do not retry blindly
    throw new Error(`SRV lookup returned no hosts for ${srvUri}; check DNS.`);
  }
  throw err;
}

Prevention

When it happens

Trigger: Constructing a MongoClient with a 'mongodb+srv://' URI whose hostname has no SRV record published, or where srvServiceName is overridden to a value with no matching SRV record. The error fires inside resolveOptions/resolveSRVRecord after resolveSrv completes with an empty array.

Common situations: Typo in the SRV hostname (e.g. 'mongodb+srv://cluser.example.com'), pointing at a host whose DNS provider never created the SRV record, using a non-SRV hostname with the +srv scheme, or a custom srvServiceName that does not match the published '_mongodb._tcp' record.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11). Data as JSON: /api/errors/3f4d9431bbbb4db2. Report an issue: GitHub.

Appendix: 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 dce7939f86)