Error
Error Code: 293

MongoDB Error 293: Invalid Replica Set Configuration

📦 MongoDB
📋

Description

Error 293, 'Invalid Seed List', indicates that the client application failed to connect to a MongoDB replica set because the provided list of initial replica set members is incorrect or inaccessible. This typically occurs during the initial connection attempt when the client tries to discover the replica set topology.
💬

Error Message

Invalid Seed List
🔍

Known Causes

4 known causes
⚠️
Incorrect Hostnames or IP Addresses
The seed list contains hostnames or IP addresses that are misspelled, non-existent, or do not resolve to active replica set members.
⚠️
Invalid Port Numbers
The port numbers specified for the replica set members in the seed list do not match the actual ports MongoDB instances are listening on.
⚠️
Network Connectivity Issues
The client application cannot reach the specified hosts due to firewall restrictions, network outages, or incorrect routing configurations.
⚠️
Replica Set Name Mismatch
The 'replicaSet' parameter in the connection string does not accurately reflect the configured name of the target MongoDB replica set.
🛠️

Solutions

4 solutions available

1. Verify Replica Set Hostnames and Ports easy

Ensure all replica set members are correctly listed with their hostnames and ports.

1
Connect to your MongoDB instance using the `mongo` shell.
mongo
2
Access the `rs.conf()` output to inspect the current replica set configuration.
rs.conf()
3
Examine the `members` array in the output. For each member, verify that the `host` field contains the correct hostname or IP address and the `port` field is the correct port number for that MongoDB instance.
// Example of a member object in rs.conf() output:
{
  "_id": 0,
  "host": "mongodb0.example.net:27017"
}
4
If any hostnames or ports are incorrect, you will need to reconfigure the replica set. This typically involves stopping the incorrect members, removing them from the replica set configuration, and then re-adding them with the correct details. For a single incorrect entry, you might be able to update it directly if you are the primary, but a full reconfigure is safer. Consult MongoDB documentation for the exact `rs.reconfig()` procedure.
/*
  WARNING: rs.reconfig() is a powerful command and can lead to data loss if used incorrectly.
  Always back up your data before attempting reconfigurations.
  Refer to official MongoDB documentation for detailed steps on rs.reconfig().
*/

2. Check for Typographical Errors in Seed List easy

Carefully review the seed list provided during replica set initialization or configuration for any typos.

1
Locate the configuration file or command used to initialize or reconfigure your replica set. This is often `mongod.conf` or the command-line arguments passed to `mongod`.
# Example from mongod.conf:
replication:
  replSetName: "myReplicaSet"
  seedList: "mongodb0.example.net:27017,mongodb1.example.net:27017,mongodb2.example.net:27017"
2
Meticulously check each hostname or IP address and port number in the `seedList` for any misspellings, extra spaces, or incorrect characters.
/*
  Ensure that "mongodb0.example.net" is spelled correctly and not "mongdodb0.example.net"
  Ensure that the port "27017" is correct and not "27071" or similar.
  No leading/trailing spaces around hostnames or ports.
*/
3
Correct any identified typos in the configuration file or command.
vim /etc/mongod.conf  # Or your specific configuration file path
4
Restart the `mongod` process for the changes to take effect. If you are reconfiguring an existing replica set, you might need to perform a `rs.reconfig()` after correcting the seed list and restarting members.
sudo systemctl restart mongod

3. Resolve Network Connectivity and DNS Issues medium

Verify that all replica set members can reach each other by hostname and port.

1
From each MongoDB server in the replica set, attempt to ping the hostnames of all other members.
ping mongodb1.example.net
2
From each MongoDB server, use `telnet` or `nc` (netcat) to test connectivity to the MongoDB port (default 27017) on all other replica set members.
telnet mongodb1.example.net 27017
# Or
nc -vz mongodb1.example.net 27017
3
If DNS resolution fails, ensure that the DNS server is correctly configured on all servers and that the hostnames are resolvable. You might consider using IP addresses in the seed list if DNS is unreliable, but this is less flexible.
# Check DNS configuration:
cat /etc/resolv.conf
4
Check firewall rules on all servers to ensure that traffic on the MongoDB port is allowed between replica set members. This includes both host-based firewalls (like `ufw` or `firewalld`) and network firewalls.
# Example for ufw:
sudo ufw allow from 192.168.1.0/24 to any port 27017
# Example for firewalld:
sudo firewall-cmd --permanent --add-port=27017/tcp
sudo firewall-cmd --reload
5
If you discover network or firewall issues, resolve them accordingly. After resolving, you may need to restart the `mongod` services on the affected nodes and potentially re-run `rs.reconfig()` if the configuration was already partially applied.
sudo systemctl restart mongod

4. Reinitialize Replica Set Configuration advanced

In cases of persistent errors or complex misconfigurations, reinitializing the replica set can be a robust solution.

1
This is a destructive operation. **BACK UP YOUR DATA FIRST.**
mongodump --archive --dbpath /var/lib/mongodb --out /backup/mongodb_backup.gz
2
Connect to the `mongo` shell on each node that is intended to be part of the replica set.
mongo
3
On each node, stop the `mongod` process.
sudo systemctl stop mongod
4
On each node, remove the existing data directory (or rename it to keep a backup). **This is the most critical step for reinitialization.**
rm -rf /var/lib/mongodb/*  # Or mv /var/lib/mongodb /var/lib/mongodb_old
5
On the intended primary node, start `mongod` with the `--replSet` option and the correct `seedList` in its configuration or command line.
# Example using command line:
mongod --replSet myReplicaSet --bind_ip localhost,<your_public_ip> --port 27017 --dbpath /var/lib/mongodb --seedList mongodb0.example.net:27017,mongodb1.example.net:27017,mongodb2.example.net:27017

# Example using mongod.conf (ensure it's correctly set up):
# sudo systemctl start mongod
6
Connect to the `mongo` shell on the primary node and initialize the replica set.
mongo
rs.initiate({
  _id: "myReplicaSet",
  members: [
    { _id: 0, host: "mongodb0.example.net:27017" },
    { _id: 1, host: "mongodb1.example.net:27017" },
    { _id: 2, host: "mongodb2.example.net:27017" }
  ]
})
7
On the other nodes, start `mongod` with the same `--replSet` option and `seedList`. They should automatically join the replica set.
# Example using command line:
mongod --replSet myReplicaSet --bind_ip localhost,<your_public_ip> --port 27017 --dbpath /var/lib/mongodb --seedList mongodb0.example.net:27017,mongodb1.example.net:27017,mongodb2.example.net:27017

# Example using mongod.conf (ensure it's correctly set up):
# sudo systemctl start mongod
8
Verify the replica set status on the primary node.
rs.status()
9
Restore your data from the backup.
mongorestore --archive=/backup/mongodb_backup.gz --dbpath /var/lib/mongodb
🔗

Related Errors

5 related errors