【发布时间】:2020-12-28 07:54:02
【问题描述】:
mongoose
.connect(
"mongodb+srv://node-sandbox:" +
process.env.MONGO_ATLAS_PW +
"@node-sandbox-2hdom.mongodb.net/test?retryWrites=true&w=majority",
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
}
)
.catch((err) => {
console.log("printing mongoose error - " + err);
});
mongoose.Promise = global.Promise;
一个 nodejs 项目在使用 CodePipeline 和 github 在 aws 上部署时显示错误,而在我的本地机器上运行时却运行良好。
错误-
printing mongoose error - MongoError: bad auth Authentication failed.
printing mongoose error - MongooseServerSelectionError: bad auth Authentication failed.
connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.37.102, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "172.31.8.154"
编辑: 我是后端开发的新手。 尝试通过邮递员连接时收到此响应 -
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
我认为 mongo 连接没有任何问题,在 mongo 控制台中它只显示一个连接。所以还有其他问题!查不出问题! 也许是一些 http/https 问题。
【问题讨论】:
-
代码看起来不错,您确定 process.env.MONGO_ATLAS_PW 在 AWS 上的值正确吗?
-
有一段时间我也在 github 中添加了 .env 文件,以便环境变量与开发环境变量相同。但它仍然无法正常工作。在aws上添加环境变量的任何其他方式? @Chcamiloam
标签: node.js github mongoose amazon-elastic-beanstalk aws-codepipeline