Cannot connect to mongodb atlas in development mode after deployment to heroku

System Information
  • Strapi Version:
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

I have recently deployed my strapi cms to heroku. and I have configured the project as mentioned in the doc of strapi deployment with heroku. After the deployment i can’t connect to my mongodb atlas in developmnet mode.
When i run ‘yarn run develop’ it gives me this error

yarn run v1.22.10
$ strapi develop
[2021-05-30T08:17:05.171Z] info File created: F:\freetoos_remastered\freetoos-backend\config\env\develop\database.js
[2021-05-30T08:17:05.174Z] info The server is restarting

[2021-05-30T08:17:38.047Z] debug ⛔️ Server wasn't able to start properly.
[2021-05-30T08:17:38.048Z] error Error connecting to the Mongo database. getaddrinfo ENOTFOUND undefined
error Command failed with exit code 1.
info Visit for documentation about this command.

here’s my prject structures.

./config/database.js looks this.

module.exports = ({ env }) => ({

  defaultConnection: 'default',

  connections: {

    default: {

      connector: 'mongoose',

      settings: {

        uri: env('DATABASE_URI'),


      options: {

        ssl: true,





it should be:

Also this error means the Domain name cant be resolved to an IP address.
If your mongo URI is can’t resolved to an ip like

yeah i have a env folder and inside that i have development and production. I forgot while posting question. It doesn’t work still.

Error connecting to the Mongo database. getaddrinfo ENOTFOUND undefined,
doesn’t work like this => uri: env(‘DATABASE_URI’),
but work like this => uri: ‘DATABASE_URI’,
how i make env work with it

You need to set the DATABASE_URL node environment variable in Heroku