ReplicaSet connection failed
srPuebla opened this issue · 1 comments
srPuebla commented
Hi,
I have deployed successfully the 3 nodes,
[root@localhost devcontainers-mongodb-replica-set-with-docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
65282c4114d5 mongo:4.2 "docker-entrypoint.s…" About an hour ago Up 15 minutes 0.0.0.0:30002->27017/tcp mongo2
f245429d27dc mongo:4.2 "docker-entrypoint.s…" About an hour ago Up 12 minutes 0.0.0.0:30003->27017/tcp mongo3
97f391716591 mongo:4.2 "docker-entrypoint.s…" About an hour ago Up 12 minutes (healthy) 0.0.0.0:30001->27017/tcp mongo1
However, if you try to connect using the replicaSet name you cant connect.
This works:
mongo mongodb://pruebauser:prueba123@localhost:30001,localhost:30002,localhost:30003/prueba
And this doesnt work (you specify the replicaSet on connection ?replicaSet=rs0):
[root@localhost devcontainers-mongodb-replica-set-with-docker]# mongo mongodb://pruebauser:prueba123@localhost:30001,localhost:30002,localhost:30003/prueba?replicaSet=rs0
MongoDB shell version v4.2.0
connecting to: mongodb://localhost:30001,localhost:30002,localhost:30003/prueba?compressors=disabled&gssapiServiceName=mongodb&replicaSet=rs0
{"t":{"$date":"2021-03-18T10:18:11.751Z"},"s":"I", "c":"NETWORK", "id":4333208, "ctx":"ReplicaSetMonitor-TaskExecutor","msg":"RSM host selection timeout","attr":{"replicaSet":"rs0","error":"FailedToSatisfyReadPreference: Could not find host matching read preference { mode: \"nearest\" } for set rs0"}}
Error: connect failed to replica set rs0/localhost:30001,localhost:30002,localhost:30003 :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1
The env file is the next below:
[root@localhost devcontainers-mongodb-replica-set-with-docker]# cat .env
# MongoDB
MONGO_URL=mongodb://mongodb:27017
MONGO_INITDB_ROOT_USERNAME=admin
MONGO_INITDB_ROOT_PASSWORD=admin123
MONGO_INITDB_DATABASE=prueba
MONGO_INITDB_USERNAME=pruebauser
MONGO_INITDB_PASSWORD=prueba123
MONGO_REPLICA_SET_NAME=rs0
sntnupl commented
Thanks for raising this issue.
It is now fixed via this commit.