简体   繁体   中英

Error connecting to the Mongo database. bad auth Authentication failed heroku + atlas mongodb + strapi

I might not have enough code here to provide.

I am currently using strapi and running my app on heroku + atlas mongodb. Everything was working fine when I was running the app with postgresql by heroku but I am migrating everything to atlas mongodb instead.

in strapi I have my config as

{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "strapi-hook-mongoose",
      "settings": {
        "client": "mongo",
        "host": "${process.env.DATABASE_HOST}",
        "port": "${process.env.DATABASE_PORT}",
        "database": "${process.env.DATABASE_NAME}",
        "username": "${process.env.DATABASE_USERNAME}",
        "password": "${process.env.DATABASE_PASSWORD}"
      },
      "options": {
        "useNullAsDefault": true,
        "ssl": "${process.env.DATABASE_SSL}"
      }
    }
  }
}

these configs are in .env which if running locally the file would look like

DATABASE_HOST=xxxxxxx-shard-00-00-xxxxxx.mongodb.net:25758,xxxxxxx-shard-00-01-xxxxxx.mongodb.net:25758,xxxxxxx-shard-00-02-xxxxxx.mongodb.net:25758/test?ssl=true&replicaSet=xxxxxxx-shard-0&authSource=admin&retryWrites=true
DATABASE_PORT=25758
DATABASE_USERNAME=xxxxx
DATABASE_PASSWORD=xxxxx
DATABASE_NAME=xxxxx
DATABASE_SSL=true

if I run it locally, it works perfectly and able to connect to DB.

so I deployed to heroku and went to heroku's setting to config vars. I configured the same vars as what I have in the .env file

I also checked atlas mongodb's ip whitelist, I whitelist to all traffics (any ip) so this shouldn't be the problem.

But as mentioned, I used the same .env locally and config vars on heroku....but on heroku I got this error message

error Error connecting to the Mongo database. bad auth Authentication failed.

Anyone has suggestions on the reason authentication would fail?

Thanks in advance for any suggestions and help.

DATABASE_SSL=true Environment Variables don't support boolean values, meaning it's passing that as a string. For now you will need to manually set that value in your config and not pass it over env in heroku.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM