Error
Error Code:
13436
MongoDB Error 13436: Server Not Replica Set Member
Description
This error indicates that a MongoDB instance is not currently acting as a primary or secondary member within a replica set. It often occurs when an application attempts to perform operations requiring a replica set context on a standalone server, or when a replica set member is in a transient or unhealthy state.
Error Message
Not Primary Or Secondary
Known Causes
4 known causesStandalone Instance Connection
Attempting to connect to a 'mongod' instance that is running as a standalone server, not configured as part of any replica set.
Replica Set Member in Transient State
The connected 'mongod' instance is part of a replica set but is currently in a state other than primary or secondary (e.g., STARTUP, RECOVERING, ARBITER, ROLLBACK).
Network Connectivity Loss
A replica set member has lost network connectivity to the majority of the replica set, causing it to step down or become unavailable for operations.
Replica Set Not Initialized
The 'mongod' instance is configured to be part of a replica set but the replica set has not yet been initialized using 'rs.initiate()'.
Solutions
3 solutions available1. Verify Replica Set Configuration and Member Status medium
Ensure the server is correctly configured as a replica set member and is healthy.
1
Connect to the MongoDB instance experiencing the error.
mongo --host <hostname> --port <port>
2
Run the `rs.status()` command to check the replica set status.
rs.status()
3
Examine the output for the problematic server. Look for:
- `stateStr`: Should be 'PRIMARY', 'SECONDARY', 'ARBITER', etc. If it's 'STARTUP', 'STARTUP2', or 'DOWN', there's a configuration or network issue.
- `health`: Should be 1 (healthy). If it's 0, there's a problem.
- `members`: Ensure the server is listed and its configuration matches other members.
- `stateStr`: Should be 'PRIMARY', 'SECONDARY', 'ARBITER', etc. If it's 'STARTUP', 'STARTUP2', or 'DOWN', there's a configuration or network issue.
- `health`: Should be 1 (healthy). If it's 0, there's a problem.
- `members`: Ensure the server is listed and its configuration matches other members.
null
4
If the server is not listed or has a health issue, check its MongoDB configuration file (`mongod.conf`) for `replication.replSetName` and ensure it's set correctly.
null
5
Restart the `mongod` service on the problematic server if configuration changes were made or if the status indicates it's not running correctly.
sudo systemctl restart mongod
2. Check Network Connectivity Between Replica Set Members medium
Verify that all replica set members can communicate with each other.
1
From the server experiencing the error, try to connect to other replica set members using `mongo`.
mongo --host <other_member_hostname> --port <other_member_port>
2
From other replica set members, try to connect to the problematic server.
mongo --host <problematic_server_hostname> --port <problematic_server_port>
3
Ensure that firewalls on all servers are configured to allow traffic on the MongoDB port (default 27017) between replica set members. This includes checking security groups in cloud environments.
null
4
Verify that DNS resolution is working correctly for all replica set member hostnames.
ping <other_member_hostname>
3. Re-initialize Replica Set Member advanced
If a member is consistently failing to join or is in a bad state, re-initializing it can resolve persistent issues.
1
Stop the `mongod` service on the problematic server.
sudo systemctl stop mongod
2
Back up any critical data from the data directory of the problematic server.
null
3
Remove the contents of the data directory (e.g., `/var/lib/mongodb`). **WARNING: This will delete all data on this server. Ensure you have backups and that this member is not the sole source of data.**
sudo rm -rf /var/lib/mongodb/*
4
Edit the `mongod.conf` file on the problematic server. Ensure `replication.replSetName` is correctly configured.
null
5
Start the `mongod` service on the problematic server.
sudo systemctl start mongod
6
Connect to the PRIMARY member of the replica set.
mongo --host <primary_hostname> --port <primary_port>
7
Add the re-initialized member to the replica set using `rs.add()`.
rs.add("<problematic_server_hostname>:<problematic_server_port>")
8
Monitor `rs.status()` on the primary to ensure the new member syncs and becomes healthy.
rs.status()