70 mongodb network_error ai_generated partial

MongoServerError: ShardNotFound: no config server primary available for shard

ID: mongodb/sharded-cluster-no-config-primary

Also available as: JSON · Markdown · 中文
70%Fix Rate
88%Confidence
1Evidence
2024-01-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
mongodb 7.0 active
mongodb 6.0 active
mongodb 5.0 active
mongodb 4.4 active

Root Cause

The config server replica set has no primary node due to network partition, election failure, or node crash.

generic

中文

配置服务器副本集由于网络分区、选举失败或节点崩溃而没有主节点。

Official Documentation

https://www.mongodb.com/docs/manual/reference/error-codes/#mongodb-error-70

Workarounds

  1. 75% success Check config server replica set status: rs.status() on the config server, then force re-election if necessary: rs.stepDown() on the current primary or rs.reconfig() to add a new member.
    Check config server replica set status: rs.status() on the config server, then force re-election if necessary: rs.stepDown() on the current primary or rs.reconfig() to add a new member.
  2. 60% success Temporarily route reads to secondary with readPreference=secondaryPreferred if writes are not critical: db.getMongo().setReadPref('secondaryPreferred')
    Temporarily route reads to secondary with readPreference=secondaryPreferred if writes are not critical: db.getMongo().setReadPref('secondaryPreferred')

中文步骤

  1. 检查配置服务器副本集状态:在配置服务器上运行rs.status(),必要时强制重新选举:在当前主节点上运行rs.stepDown()或使用rs.reconfig()添加新成员。
  2. 如果写操作不关键,临时将读操作路由到从节点:db.getMongo().setReadPref('secondaryPreferred')

Dead Ends

Common approaches that don't work:

  1. 90% fail

    The mongos is not the issue; the config server replica set needs repair.

  2. 95% fail

    Connection pool size does not affect config server primary availability.