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

  1. Update to the latest driver release that supports your topology.
  2. Avoid patching SDAM internals; if necessary, re-run with stock internals to confirm.
  3. 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

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


AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04). Data as JSON: /data/errors/95c68f5dfa3d0cec.json. Report an issue: GitHub.