【问题标题】:Error connecting to the Mongo database. bad auth Authentication failed heroku + atlas mongodb + strapi连接到 Mongo 数据库时出错。 bad auth 身份验证失败 heroku + atlas mongodb + strapi
【发布时间】:2020-06-07 17:52:21
【问题描述】:

我可能没有足够的代码来提供。

我目前正在使用 strpi 并在 heroku + atlas mongodb 上运行我的应用程序。当我使用 heroku 的 postgresql 运行应用程序时,一切正常,但我正在将所有内容迁移到 atlas mongodb。

在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}"
      }
    }
  }
}

这些配置在 .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

如果我在本地运行它,它可以完美运行并且能够连接到数据库。

所以我部署到 heroku 并转到 heroku 的设置来配置变量。我配置了与.env 文件中相同的变量

我还检查了 atlas mongodb 的 ip 白名单,我将所有流量(任何 ip)列入白名单,所以这应该不是问题。

但如前所述,我在本地使用了相同的 .env,在 heroku 上使用了 config vars....但在 heroku 上我收到了这个错误消息

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

有人对身份验证失败的原因有什么建议吗?

提前感谢您的任何建议和帮助。

【问题讨论】:

    标签: node.js mongodb heroku strapi mongodb-atlas


    【解决方案1】:

    DATABASE_SSL=true 环境变量不支持布尔值,这意味着它将它作为字符串传递。现在,您需要在配置中手动设置该值,而不是将其传递给 heroku 中的 env。

    【讨论】:

      猜你喜欢
      • 2021-01-18
      • 1970-01-01
      • 2021-11-03
      • 2017-06-18
      • 2019-03-12
      • 2016-07-05
      • 1970-01-01
      • 2015-08-29
      • 2019-05-09
      相关资源
      最近更新 更多