[英]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.