{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L76-L112","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the hostname with: dig SRV _mongodb._tcp.<your-host> (or nslookup -type=SRV _mongodb._tcp.<your-host>) and confirm it returns entries.","Correct the hostname in the mongodb+srv:// URI.","If using a custom service name, ensure srvServiceName matches the published SRV service label, or remove it to use the default 'mongodb'.","If SRV records genuinely should be empty, switch to a standard mongodb:// URI listing hosts explicitly."],"exampleFix":"// before\nconst c = new MongoClient('mongodb+srv://cluser.example.com/db');\n// after\nconst c = new MongoClient('mongodb+srv://cluster.example.com/db');","handlingStrategy":"validation","validationCode":"import { promises as dns } from 'dns';\n\nasync function assertSrvResolvable(srvHost: string, srvServiceName = 'mongodb') {\n  const name = `_${srvServiceName}._tcp.${srvHost}`;\n  const records = await dns.resolveSrv(name);\n  if (!records || records.length === 0) {\n    throw new Error(`No SRV records found at ${name}`);\n  }\n  return records;\n}\n\n// call before constructing MongoClient for mongodb+srv URIs\nawait assertSrvResolvable('cluster.example.com');","typeGuard":"function isSrvUri(uri: string): boolean {\n  return /^mongodb\\+srv:\\/\\//i.test(uri);\n}","tryCatchPattern":"try {\n  const client = new MongoClient(srvUri);\n  await client.connect();\n} catch (err) {\n  if (err instanceof MongoAPIError && /No addresses found at host/.test(err.message)) {\n    // surface a DNS-config actionable message, do not retry blindly\n    throw new Error(`SRV lookup returned no hosts for ${srvUri}; check DNS.`);\n  }\n  throw err;\n}","preventionTips":["Run `dig SRV _mongodb._tcp.<host>` during deploy/CI to verify the record exists.","Centralize connection string construction in one config module so typos surface once.","Prefer standard mongodb:// URIs in environments without DNS SRV control."],"tags":["dns","connection-string","srv","mongodb-plus-srv"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}