{"id":"3f4d9431bbbb4db2","repo":"mongodb/node-mongodb-native","slug":"no-addresses-found-at-host","errorCode":null,"errorMessage":"No addresses found at host","messagePattern":"No addresses found at host","errorType":"exception","errorClass":"MongoAPIError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":94,"sourceCode":" */\nexport async function resolveSRVRecord(options: MongoOptions): Promise<HostAddress[]> {\n  if (typeof options.srvHost !== 'string') {\n    throw new MongoAPIError('Option \"srvHost\" must not be empty');\n  }\n\n  // Asynchronously start TXT resolution so that we do not have to wait until\n  // the SRV record is resolved before starting a second DNS query.\n  const lookupAddress = options.srvHost;\n  const txtResolutionPromise = resolveTxt(lookupAddress);\n\n  txtResolutionPromise.then(undefined, squashError); // rejections will be handled later\n\n  const hostname = `_${options.srvServiceName}._tcp.${lookupAddress}`;\n  // Resolve the SRV record and use the result as the list of hosts to connect to.\n  const addresses = await resolveSrv(hostname);\n\n  if (addresses.length === 0) {\n    throw new MongoAPIError('No addresses found at host');\n  }\n\n  for (const { name } of addresses) {\n    checkParentDomainMatch(name, lookupAddress);\n  }\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    }","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L76-L112","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the SRV record exists: dig _mongodb._tcp.<host> SRV or nslookup -type=srv _mongodb._tcp.<host>.","If the cluster does not publish SRV records, switch to a standard mongodb:// URI listing hosts directly.","Confirm srvServiceName (if overridden) matches the service name configured in DNS.","Check with your DNS/cluster admin that records were created and propagated."],"exampleFix":"// before\nconst uri = 'mongodb+srv://mycluster.selfhosted.example/db'; // no SRV record\n// after\nconst uri = 'mongodb://host1:27017,host2:27017,host3:27017/db?replicaSet=mycluster';","handlingStrategy":"validation","validationCode":"import { promises as dns } from 'dns';\nasync function hasSrvRecord(host: string, service = 'mongodb'): Promise<boolean> {\n  try {\n    const records = await dns.resolveSrv(`_${service}._tcp.${host}`);\n    return records.length > 0;\n  } catch {\n    return false;\n  }\n}\n// gate before connect for mongodb+srv URIs","typeGuard":null,"tryCatchPattern":"try {\n  await client.connect();\n} catch (e) {\n  if (e instanceof MongoAPIError && /No addresses found at host/.test(e.message)) {\n    // fall back to a standard host list URI, or alert ops\n  }\n  throw e;\n}","preventionTips":["Confirm SRV records exist with dig/nslookup before deploying.","Prefer mongodb:// with explicit hosts for clusters without SRV.","Monitor DNS health in CI for Atlas-style hostnames."],"tags":["connection-string","dns","srv","network"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}