{"record":{"id":"f6e1adf34e8bcdcc","repo":"mongodb/node-mongodb-native","slug":"options-for-srvpoller-must-exist-and-include-srvho","errorCode":null,"errorMessage":"Options for SrvPoller must exist and include srvHost","messagePattern":"Options for SrvPoller must exist and include srvHost","errorType":"exception","errorClass":"MongoRuntimeError","httpStatus":null,"severity":"error","filePath":"src/sdam/srv_polling.ts","lineNumber":55,"sourceCode":"export class SrvPoller extends TypedEventEmitter<SrvPollerEvents> {\n  srvHost: string;\n  rescanSrvIntervalMS: number;\n  heartbeatFrequencyMS: number;\n  haMode: boolean;\n  generation: number;\n  srvMaxHosts: number;\n  srvServiceName: string;\n  _timeout?: NodeJS.Timeout;\n\n  /** @event */\n  static readonly SRV_RECORD_DISCOVERY = 'srvRecordDiscovery' as const;\n\n  constructor(options: SrvPollerOptions) {\n    super();\n    this.on('error', noop);\n\n    if (!options || !options.srvHost) {\n      throw new MongoRuntimeError('Options for SrvPoller must exist and include srvHost');\n    }\n\n    this.srvHost = options.srvHost;\n    this.srvMaxHosts = options.srvMaxHosts ?? 0;\n    this.srvServiceName = options.srvServiceName ?? 'mongodb';\n    this.rescanSrvIntervalMS = 60000;\n    this.heartbeatFrequencyMS = options.heartbeatFrequencyMS ?? 10000;\n\n    this.haMode = false;\n    this.generation = 0;\n\n    this._timeout = undefined;\n  }\n\n  get srvAddress(): string {\n    return `_${this.srvServiceName}._tcp.${this.srvHost}`;\n  }\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/sdam/srv_polling.ts#L37-L73","documentation":"Thrown by the SrvPoller constructor (src/sdam/srv_polling.ts:55) as MongoRuntimeError when the options object is missing or has no srvHost field. SrvPoller resolves hostnames for mongodb+srv:// connection strings by polling DNS SRV records; it requires a hostname to poll. This is an internal component constructed by the topology during SRV-based connection setup.","triggerScenarios":"Connecting with mongodb+srv:// but the parsed URI produced no srvHost (e.g. an empty or malformed SRV URI), or internal code constructing SrvPoller without options. Reached only on mongodb+srv:// connections.","commonSituations":"Malformed mongodb+srv:// URI missing the hostname (e.g. mongodb+srv:///dbname), corrupted URI parsing, or a driver bug.","solutions":["Ensure the mongodb+srv:// URI has a valid hostname: mongodb+srv://cluster.example.net/dbname.","Verify DNS resolution of the SRV hostname works (nslookup or dig).","If the URI looks correct, report to driver maintainers as an internal error."],"exampleFix":"// before\nconst client = new MongoClient('mongodb+srv:///test');\n// after\nconst client = new MongoClient('mongodb+srv://cluster.example.net/test');","handlingStrategy":"validation","validationCode":"function assertSrvUri(uri) {\n  if (uri.startsWith('mongodb+srv://')) {\n    const host = uri.slice('mongodb+srv://'.length).split('/')[0];\n    if (!host) throw new Error('mongodb+srv URI missing hostname');\n  }\n}","typeGuard":"function hasSrvHost(uri): boolean {\n  return /^mongodb\\+srv:\\/\\/[^/]+/.test(uri);\n}","tryCatchPattern":"try {\n  await client.connect();\n} catch (e) {\n  if (e instanceof MongoRuntimeError && /srvHost/.test(e.message)) {\n    // fix the URI to include a hostname\n  }\n  throw e;\n}","preventionTips":["Validate mongodb+srv:// URIs include a hostname before connecting.","Test SRV hostnames with dig/nslookup in CI.","Avoid hand-building SRV URIs from templated parts that may drop the host."],"tags":["sdam","srv","connection-string","dns","configuration"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}