0

I am trying to connect a MongoDB URI to the strapi backend. I am able to connect with the main URL but when I created a .env.development variable, I am not able to connect to the database.

 {
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "mongoose",
      "settings": {
        "uri": "${process.env.DATABASE_URI || ''}"
      },
      "options": {
        "ssl": true
      }
    }
  }
}

2 Answers2

0

Ok, new plan.

try that :

npm install --save dotenv

require('dotenv').config()

{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "mongoose",
      "settings": {
        "uri": `${process.env.DATABASE_URI || ''}`
  },
  "options": {
    "ssl": true
  }
}

} }

Wonkledge
  • 1,732
  • 7
  • 16
0

I am new to programming and strapi. Just want to share i have problem with deploying to heroku with the same problem. I fix it with this:

{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "mongoose",
      "settings": {
        "uri": "${process.env.DATABASE_URI}",
        "database": "${process.env.DATABASE_NAME}"
      },
      "options": {
        "ssl": true
      }
    }
  }
}

If you are deploying to heroku please check the environment variables. When I set environment variables using heroku cli it does not save the whole string. I have to copy and paste to the heroku website directly.

DedaDev
  • 4,441
  • 2
  • 21
  • 28
Rendy
  • 1
  • on heroku, for that particular app, you can navigate to settings -> Config Vars and add the config variables like DATABASE_URI and DATABASE_NAME – Sayan Mukherjee May 26 '20 at 02:06