Error
Error Code:
93
MongoDB Error 93: Invalid Replica Set Configuration
Description
Error 93, 'Invalid Replica Set Config', indicates that the configuration provided for a MongoDB replica set is syntactically or semantically incorrect. This error commonly occurs during replica set initialization, when attempting to reconfigure an existing replica set, or when a new member tries to join with an incompatible configuration.
Error Message
Invalid Replica Set Config
Known Causes
4 known causesSyntax Errors in Config Document
The replica set configuration document (e.g., in `rs.initiate()` or `rs.reconfig()`) contains JSON syntax errors or malformed fields.
Incorrect Member Definitions
One or more members defined in the replica set configuration have missing or incorrect hostnames, ports, or other essential properties.
Duplicate Members or IDs
The configuration attempts to add members with duplicate hostnames, ports, or uses non-unique `_id` values for replica set members.
Incompatible Protocol Version
The `protocolVersion` specified in the configuration is not supported by all replica set members or is invalid for the MongoDB version.
Solutions
4 solutions available1. Reconfigure Replica Set with Correct Settings medium
Correctly define replica set members, hostnames, and ports in the configuration.
1
Connect to the primary node of the replica set using the `mongo` shell.
mongo --host <primary_host> --port <primary_port>
2
Initiate the replica set reconfiguration process.
rs.reconfig()
3
Provide a valid replica set configuration object. Ensure all `host` entries correctly reflect the DNS-resolvable hostnames or IP addresses of your replica set members and that the `port` is correct. If using IPs, ensure they are static and consistently reachable. If using hostnames, verify DNS resolution from all replica set members.
var config = {
_id: "myReplicaSetName",
version: 1,
members: [
{ _id: 0, host: "mongo1.example.com:27017" },
{ _id: 1, host: "mongo2.example.com:27017" },
{ _id: 2, host: "mongo3.example.com:27017" }
]
};
rs.reconfig(config);
4
If the configuration was successfully applied, you will see a confirmation message. If not, review the output for specific errors indicating what is invalid (e.g., duplicate hostnames, incorrect ports, unreachable members).
2. Verify Network Connectivity and Hostnames medium
Ensure all replica set members can reach each other using their configured hostnames and ports.
1
From each replica set member, attempt to connect to every other member using the configured hostname and port.
mongo --host <other_member_hostname> --port <other_member_port>
2
If any connection fails, investigate DNS resolution or firewall rules. Ensure that the hostname specified in the replica set configuration resolves to the correct IP address on all members.
ping <member_hostname>
3
Check that the specified ports are open for communication between replica set members. Use `telnet` or `nc` for this purpose.
telnet <member_hostname> <member_port>
4
If using hostnames, ensure that `/etc/hosts` files (or equivalent) on each node are consistent or that DNS is correctly configured and propagated.
3. Check for Duplicate Member Configurations easy
Ensure no replica set member is listed more than once in the configuration.
1
Connect to the primary node of the replica set using the `mongo` shell.
mongo --host <primary_host> --port <primary_port>
2
Retrieve the current replica set configuration.
rs.conf()
3
Carefully examine the `members` array in the output. Identify if any `host` entries (including port) are duplicated. If duplicates are found, proceed to reconfigure the replica set with a corrected configuration as described in the 'Reconfigure Replica Set with Correct Settings' solution.
4. Reset and Reinitialize the Replica Set advanced
A more drastic step to completely rebuild the replica set configuration.
1
On *all* members of the replica set, stop the `mongod` process.
sudo systemctl stop mongod
2
On *all* members, remove the replica set configuration file (typically `mongod.conf`) and any data files associated with the replica set (e.g., the `dbpath`). **WARNING: This will result in data loss if not properly backed up.**
sudo rm -rf /var/lib/mongodb/* # Adjust path to your dbpath
sudo rm /etc/mongod.conf # Adjust path to your config file
3
On the node intended to be the initial primary, create a new configuration file (e.g., `/etc/mongod.conf`) with the `replication` settings for the replica set.
replication:
replSetName: "myReplicaSetName"
storage:
dbPath: /var/lib/mongodb
net:
port: 27017
bindIp: 0.0.0.0
4
Start the `mongod` process on the initial primary node.
sudo systemctl start mongod
5
Connect to the initial primary using the `mongo` shell and initialize the replica set.
mongo --host <initial_primary_host> --port 27017
6
Initialize the replica set with the desired configuration, ensuring correct hostnames and ports for all members.
rs.initiate( {
_id: "myReplicaSetName",
members: [
{ _id: 0, host: "mongo1.example.com:27017" },
{ _id: 1, host: "mongo2.example.com:27017" },
{ _id: 2, host: "mongo3.example.com:27017" }
]
} );
7
On all other nodes, create their respective configuration files and start the `mongod` processes. They should automatically join the replica set.