{"id":"ae927285473ec515","repo":"mongodb/node-mongodb-native","slug":"topology-cannot-be-constructed-from-json-stringi","errorCode":null,"errorMessage":"Topology cannot be constructed from ${JSON.stringify(seed)}","messagePattern":"Topology cannot be constructed from (.+?)","errorType":"exception","errorClass":"MongoRuntimeError","httpStatus":null,"severity":"error","filePath":"src/sdam/topology.ts","lineNumber":276,"sourceCode":"      hosts: [HostAddress.fromString('localhost:27017')],\n      ...Object.fromEntries(DEFAULT_OPTIONS.entries())\n    };\n\n    if (typeof seeds === 'string') {\n      seeds = [HostAddress.fromString(seeds)];\n    } else if (!Array.isArray(seeds)) {\n      seeds = [seeds];\n    }\n\n    const seedlist: HostAddress[] = [];\n    for (const seed of seeds) {\n      if (typeof seed === 'string') {\n        seedlist.push(HostAddress.fromString(seed));\n      } else if (seed instanceof HostAddress) {\n        seedlist.push(seed);\n      } else {\n        // FIXME(NODE-3483): May need to be a MongoParseError\n        throw new MongoRuntimeError(`Topology cannot be constructed from ${JSON.stringify(seed)}`);\n      }\n    }\n\n    const topologyType = topologyTypeFromOptions(options);\n    const topologyId = globalTopologyCounter++;\n\n    const selectedHosts =\n      options.srvMaxHosts == null ||\n      options.srvMaxHosts === 0 ||\n      options.srvMaxHosts >= seedlist.length\n        ? seedlist\n        : shuffle(seedlist, options.srvMaxHosts);\n\n    const serverDescriptions = new Map();\n    for (const hostAddress of selectedHosts) {\n      serverDescriptions.set(hostAddress.toString(), new ServerDescription(hostAddress));\n    }\n","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/sdam/topology.ts#L258-L294","documentation":"Thrown by the `Topology` constructor while building the seedlist: each seed must be either a string or a `HostAddress` instance (topology.ts:274). Any other type (number, plain object without host info, null element) cannot be turned into a server address.","triggerScenarios":"Passing MongoClient a seedlist containing a non-string/non-HostAddress entry, e.g. `new MongoClient([{ host: 'x' }])` or a numeric port-only entry; an object that is not a HostAddress.","commonSituations":"Constructing a seedlist dynamically and including a raw config object; migrating code that previously accepted looser seed shapes; a deserialized JSON array whose objects lost their HostAddress type.","solutions":["Pass seeds as `host:port` strings, or wrap them with `HostAddress.fromString(...)`.","Filter/map your seedlist to strings before passing it to MongoClient.","Use the standard connection-string URI form to avoid manual seed construction."],"exampleFix":"// before\nnew MongoClient([{ host: 'localhost', port: 27017 }]);\n// after\nnew MongoClient('mongodb://localhost:27017');","handlingStrategy":"validation","validationCode":"function normalizeSeeds(seeds) {\n  return seeds.map(s => typeof s === 'string' ? HostAddress.fromString(s) : s)\n    .filter(s => s instanceof HostAddress);\n}","typeGuard":"function isHostSeed(s) {\n  return typeof s === 'string' || s instanceof HostAddress;\n}","tryCatchPattern":null,"preventionTips":["Pass a connection-string URI instead of manual seed arrays.","Map all seeds through HostAddress.fromString before construction.","Drop or reject non-string/non-HostAddress entries early."],"tags":["configuration","connection-string","sdam"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}