Buy @ Amazon

Search This Blog

September 5, 2020

Fix Timeout Error Connecting To MongoDB Atlas

 I am at the moment dabbling with Strapi, which is a headless CMS written using Javascript. I love MongoDB and a fanboy of managed services. Getting to know that MongoDB has launched MongoDB Atlas as a managed service for cloud, I wanted to give it a try.

I had configured Strapi to use MongoDB Atlas as its backend and it worked as expected. The configuration looked like below (note that it uses mongoose library as connector to work with MongoDB Atlas):

As I was working on Strapi in development mode (it restarts its server after code changes), the server restart failed with an error message like below:


My favorite Stackoverflow or MongoDB forum didn't come to my rescue this time. As it turns out, setting the srv to false and replacing the MongoDB Atlas service name with comma separated values of individual node's URI:PORT, worked. I really don't like to configure things this way, as the former is more elegant approach. But until things are set right at MongoDB Atlas (as I see it), this should serve as a workaround. The new MongoDB connection configuration looks like below:

Happy coding!!..

No comments:

Post a Comment

Like it or hate it, feel free to share your feedback. Cheers!