If you’ve encountered this frustrating timeout error while working with MongoDB, you’re not alone! The "Server selection timed out after 30000 ms" message indicates that MongoDB couldn’t connect within the expected time.
Solution-1 : ( if you use mongoose)>
you can update your mongoDB connection url with replicaSet=rs0 query.
Solution-2 : (if you use docker-compose service)>
_you can update your mongo service with the "mongod replSet rs0". you can also include entrypoint in your service.
Solution-3 : (if you use SSH shell)>
just use the bellow command to solve the issue by set replca.
docker exec -it your_mongo_service mongosh
then set the bellow commands
rs.initiate()
rs.status()
Top comments (0)