MongoDB authentication failed for Replica Set

Hi,

the error you’re receiving is what we call a server selection error. When you run any operation, the driver selects a suitable server to run the command on, based on the type of command and the read preference you’ve stated. In your case, the error detail (“Failed to resolve ‘mongodb-1’”) indicates that this error originated in the base implementation of libmongoc, see here: mongo-c-driver/mongoc-client.c at 282f110565239a0d5d91f1e5e2f91ba4bee57dc7 · mongodb/mongo-c-driver · GitHub.

Looking at the replication stats that you posted, I can see that the host names for the two secondaries are mongodb-2 and mongodb-3, which is consistent with the error message. It looks like these host names don’t resolve to any hosts on your application server, leading to the connection error seen above as the server is not able to connect to any of the hosts in the replica set.

Please either reconfigure your replica set to use IP addresses, or ensure that the host names used in the replica set config resolve on all machines that are supposed to connect to any server from the replica set.

1 Like