{"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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/sdam/srv_polling.ts#L37-L73","documentation":"The `SrvPoller` constructor requires an options object containing a `srvHost` string (srv_polling.ts:54). SrvPoller is `@internal` and performs periodic DNS SRV record lookups for `mongodb+srv://` URIs to discover cluster hosts. Without a srvHost it cannot build the SRV query name.","triggerScenarios":"Internal construction of SrvPoller with missing options or a srvHost that is empty/undefined; a `mongodb+srv://` URI whose host portion parsed to empty; misconfigured client options reaching the poller.","commonSituations":"Malformed SRV connection string (`mongodb+srv:///dbname` with no host); programmatic client construction without a host; a bug in URI parsing on older driver versions.","solutions":["Use a well-formed `mongodb+srv://cluster.example.net/dbname` URI with a real SRV hostname.","If not using SRV discovery, use a standard `mongodb://host:port` URI instead.","Update the driver and report the URI if the error persists with a valid-looking SRV host."],"exampleFix":"// before\nconst client = new MongoClient('mongodb+srv:///mydb');\n// after\nconst client = new MongoClient('mongodb+srv://cluster.example.net/mydb');","handlingStrategy":"validation","validationCode":"function assertSrvUri(uri) {\n  if (uri.startsWith('mongodb+srv://') && uri.replace('mongodb+srv://', '').split('/')[0] === '') {\n    throw new TypeError('mongodb+srv URI must include a host');\n  }\n}","typeGuard":"function hasSrvHost(uri) {\n  return !uri.startsWith('mongodb+srv://') || /mongodb\\+srv:\\/\\/[^/]+/.test(uri);\n}","tryCatchPattern":null,"preventionTips":["Validate mongodb+srv URIs contain a host segment at config load.","Prefer full URIs over programmatic option construction.","Test connection strings in a staging cluster before deploy."],"tags":["sdam","configuration","internal","connection-string"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}