简体   繁体   English

连接到 Mongo 数据库时出错。 错误的身份验证失败 heroku + atlas mongodb + stripi

[英]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.我目前正在使用 Strapi 并在 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.当我通过 heroku 使用 postgresql 运行应用程序时,一切正常,但我正在将所有内容迁移到 atlas mongodb。

in strapi I have my config as在 Strapi 我有我的配置

{
  "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这些配置在.env ,如果在本地运行,文件看起来像

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.所以我部署到heroku并转到heroku的设置来配置变量。 I configured the same vars as what I have in the .env file我配置了与.env文件中相同的变量

I also checked atlas mongodb's ip whitelist, I whitelist to all traffics (any ip) so this shouldn't be the problem.我还检查了 atlas mongodb 的 ip 白名单,我将所有流量(任何 ip)列入白名单,所以这应该不是问题。

But as mentioned, I used the same .env locally and config vars on heroku....but on heroku I got this error message但如前所述,我在本地使用了相同的.env并在 heroku 上使用了config vars ....但是在 heroku 上我收到了此错误消息

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. DATABASE_SSL=true环境变量不支持布尔值,这意味着它将作为字符串传递。 For now you will need to manually set that value in your config and not pass it over env in heroku.现在,您需要在配置中手动设置该值,而不是通过 heroku 中的 env 传递它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 mongo shell 的 MongoDB 图集:“错误:错误的身份验证:身份验证失败。” 什么可能导致此身份验证失败? - MongoDB atlas through mongo shell: “Error: bad auth : Authentication failed.” what could possibly cause this Authentication failure? Mongodb + Atlas: 'bad auth Authentication failed.', code: 8000, - Mongodb + Atlas: 'bad auth Authentication failed.', code: 8000, MongoDb Atlas 未连接到 Heroku - MongoDb Atlas not connecting to Heroku 连接到 atlas mongo 数据库 - connecting to atlas mongo database “Mongo 错误:身份验证失败”无法从 MongoDB Atlas 读取数据 - “Mongo Error : Authentication failed” can't read datas from MongoDB Atlas 错误信息:MongoServerError: bad auth:Authentication failed - Error message : MongoServerError: bad auth :Authentication failed 命令错误: ( MongoServerError: bad auth: Authentication failed ) - Command Error : ( MongoServerError: bad auth : Authentication failed ) 将 Elastic Beanstalk 上的 web 服务器与 MongoDB Atlas 上的数据库服务器连接时出错 - Error connecting web server on Elastic Beanstalk with database server on MongoDB Atlas Heroku App连接Atlas MongoDB云服务 - Connecting Heroku App to Atlas MongoDB Cloud service 将 node.js 应用程序连接到 mongoDb Atlas 数据库时出错 - Error in connecting node.js app to mongoDb Atlas database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM