MongoDB Timeout error while connecting with replicaset
If you are facing Timed out after 30000 ms while while waiting for a server, here are few solutions you need to check.
- check the docker configuration is proper
- check any other versions of mongo is running in your machine, if you installed community edition and its running it might fail in connecting replicaset
- check connection string proper
If there is other mongo service running use below command to stop it and then try to connect to mongo
brew services stop mongodb/brew/mongodb-community@6.0
Replica set configuration
Add below script in docker-compose.yml file
version: '1.0'
services:
mongo:
hostname: mongo
container_name: mongo-workflowforms
image: mongo:4.2.0
volumes:
- ~/mongors/data1:/mongodata/db
- ./rs-init.sh:/scripts/rs-init.sh
networks:
- mongors-network
ports:
- "27017:27017"
restart: always
entrypoint:
- "/usr/bin/mongod"
- "--bind_ip_all"
- "--replSet"
- "testdb"
networks:
mongors-network:
driver: bridge
Add below code in rs-init.sh
#!/bin/bash
mongo <<EOF
var config = {
"_id": "testdb",
"version": 1,
"members": [
{
"_id": 1,
"host": "localhost:27017",
"priority": 3
}
]
};
rs.initiate(config, { force: true });
rs.status();
EOF
while connecting to mongo db give testdb as replicaset name.
If you are still facing the issue please post your logs in comments section. we'll try to solve the issue you are facing
Comments
Post a Comment