I created a strapi website using yarn create strapi-app velankannimatha
and chose the mongo as the database. I created a DB in MongoDB atlas called velankannimathadb
.
I pushed the site to Heroku after setting the config vars (i.e. DATABASE_URI
and DATABASE_NAME
).
But the application keeps crashing. When I checked the logs it says
Server wasn't able to start properly. Error connecting to the Mongo database. Server selection timed out after 30000 ms
I am able to access DB locally (in development mode). It only fails when running from Heroku. Any help is much appreciated
It's working now. What went wrong was that I was using MongoDB version 2.2.12 or later
(as per documentation). When I switched to version 3.6 or later
and used the updated connection string, everything worked.
Also, adding the connection string as config vars from terminal causes issues, even if it gets saved, some characters are missing. So I added them from the browser.
This article on medium helped a lot too.