Error
Error Code:
13435
MongoDB Error 13435: Replica Set Primary Unavailable
Description
This error indicates that the MongoDB instance you are connected to is not the primary member of its replica set, and critically, no other secondary members are considered healthy or available to become primary. It commonly occurs when a replica set has lost its primary and is unable to elect a new one, often due to insufficient healthy members or network issues.
Error Message
Not Primary No Secondary Ok
Known Causes
4 known causesPrimary Member Failure
The primary `mongod` instance has crashed, been explicitly shut down, or become unresponsive.
Network Isolation
The primary member is isolated from other replica set members due to network partitioning or connectivity issues, preventing communication and election.
Insufficient Healthy Members
There are not enough healthy, reachable replica set members to form a quorum and successfully elect a new primary.
Delayed Election
A primary election is currently in progress or has failed to complete within the expected timeframe due to various internal or external factors.
Solutions
4 solutions available1. Verify Replica Set Health and Connectivity easy
Check the status of all replica set members and ensure network connectivity between them.
1
Connect to any MongoDB instance within the replica set using the `mongosh` shell.
mongosh
2
Run the `rs.status()` command to get a detailed status of the replica set.
rs.status()
3
Examine the output for any members that are not in an `PRIMARY` or `SECONDARY` state. Pay attention to the `stateStr` field for each member. Look for any error messages or connection issues reported.
4
If connectivity issues are suspected, use `ping` or `telnet` from the machine experiencing the error to the hostnames/IP addresses and ports of other replica set members. Ensure firewalls are not blocking traffic on the MongoDB port (default 27017).
ping <replica_set_member_hostname_or_ip>
telnet <replica_set_member_hostname_or_ip> 27017
2. Initiate a Stepdown of the Current Primary medium
Force the current primary to step down, allowing another member to become primary.
1
Connect to the current primary MongoDB instance using `mongosh`.
mongosh
2
Execute the `rs.stepDown()` command. You can optionally specify a duration (in seconds) for how long the current primary should wait before stepping down (e.g., `rs.stepDown(60)` to wait 60 seconds). A shorter duration is often preferred for quicker failover.
rs.stepDown()
3
Monitor the replica set status using `rs.status()` to confirm that a new primary has been elected. This process can take a few seconds to a couple of minutes depending on your replica set configuration and network latency.
rs.status()
3. Restart a Stuck or Unresponsive Replica Set Member medium
Restart a specific member that is not participating correctly in the replica set.
1
Identify the replica set member that is experiencing issues or is in an unexpected state (e.g., not reporting in `rs.status()`).
2
Gracefully shut down the MongoDB service on that specific member. The command depends on your operating system and installation method.
# For systemd (Ubuntu/Debian/CentOS/RHEL 7+)
sudo systemctl stop mongod
# For init.d (older systems)
sudo service mongod stop
3
Wait for the shutdown to complete. Check the MongoDB logs for confirmation.
4
Start the MongoDB service on that member again.
# For systemd
sudo systemctl start mongod
# For init.d
sudo service mongod start
5
Monitor the replica set status using `rs.status()` from another member to ensure the restarted member rejoins the replica set and eventually reaches a `SECONDARY` or `PRIMARY` state.
rs.status()
4. Review and Adjust Replica Set Configuration advanced
Examine the replica set configuration for potential issues like incorrect member priorities or network settings.
1
Connect to the current primary MongoDB instance using `mongosh`.
mongosh
2
Fetch the current replica set configuration.
rs.conf()
3
Carefully review the `members` array in the configuration. Check the `host` and `port` for each member to ensure they are correct and resolvable. Verify `priority` settings; a `priority` of 0 means a member cannot become primary. Ensure that at least one member has a `priority` greater than 0.
4
Also, check `votes`. A majority of members with votes must be available for an election to succeed. Ensure that `settings.electionTimeoutMillis` is appropriately set and not too low, which can cause premature elections.
5
If any changes are needed, use `rs.reconfig()` to apply them. **Caution:** Incorrect configuration can lead to further issues. It's highly recommended to test changes in a non-production environment first.
var cfg = rs.conf();
// Modify cfg object as needed
rs.reconfig(cfg);