mongodb/node-mongodb-native · error · MongoRuntimeError
unexpected topology type: ${topologyDescription.type} (this
Error message
unexpected topology type: ${topologyDescription.type} (this should never happen). Please file a bug in the Node driver Jira project. What it means
The `default` branch of the topology-type switch in `readPreferenceServerSelector`, guarded by a `never` exhaustive check on `topologyDescription.type` (server_selection.ts:407). It indicates an SDAM topology type the selector does not recognize; the message asks for a bug report. Under normal operation the type is always one of Single, ReplicaSetNoPrimary, ReplicaSetWithPrimary, Sharded, Unknown, or LoadBalanced.
Source
Thrown at src/sdam/server_selection.ts:409
deprioritized: DeprioritizedServers
): ServerDescription[] {
switch (topologyDescription.type) {
case 'Single':
return latencyWindowReducer(topologyDescription, servers.filter(knownFilter));
case 'ReplicaSetNoPrimary':
case 'ReplicaSetWithPrimary':
return secondarySelector(readPreference, topologyDescription, servers, deprioritized);
case 'Sharded': {
const selectable = filterDeprioritized(servers, deprioritized);
return latencyWindowReducer(topologyDescription, selectable.filter(knownFilter));
}
case 'Unknown':
return [];
case 'LoadBalanced':
return servers.filter(loadBalancerFilter);
default: {
const _exhaustiveCheck: never = topologyDescription.type;
throw new MongoRuntimeError(
`unexpected topology type: ${topologyDescription.type} (this should never happen). Please file a bug in the Node driver Jira project.`
);
}
}
};
}
View on GitHub (pinned to 3366c21a63)
Solutions
- Update to the latest driver release that supports your topology.
- Avoid patching SDAM internals; if necessary, re-run with stock internals to confirm.
- File a bug with the driver version, topology, and the offending type value.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await client.db().command({ ping: 1 });
} catch (e) {
if (e instanceof MongoRuntimeError && /unexpected topology type/.test(e.message)) {
// update driver and report; this is an internal invariant
}
throw e;
} Prevention
- Keep the driver version current with your server topology.
- Do not monkeypatch SDAM internals.
- Report occurrences with the topology description and driver version.
When it happens
Trigger: A new topology type was introduced without a selector case; internal state corruption setting type to an out-of-enum value; an incompatible driver fork.
Common situations: Running an outdated driver against a newer server topology feature; monkeypatching SDAM internals.
Related errors
- ConnectionPool.clear() called in load balanced mode with no
- Service generations are required in load balancer mode.
- client.connect did not create a topology but also did not th
- ServerDescription must be provided with a non-empty address
- unexpected readPreference=${mode} (should never happen). Pl
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/95c68f5dfa3d0cec.json.
Report an issue: GitHub.