DEV Community

Cover image for MongooseServerSelectionError: 🚨Server selection timed out after 30000 ms
Sarwar Hossain
Sarwar Hossain

Posted on

MongooseServerSelectionError: 🚨Server selection timed out after 30000 ms

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.

Image description

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.

Image description

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
Enter fullscreen mode Exit fullscreen mode

then set the bellow commands

rs.initiate()

rs.status()

Enter fullscreen mode Exit fullscreen mode

Top comments (0)