部署期间MongoDB身份验证错误,本地运行时没有错误

问题描述 投票:0回答:1

部署过程中出现以下错误:

5:30:38 PM: [nodemon] starting `node server.js`
5:30:39 PM: Server listening on http://localhost:3000
5:30:39 PM: /opt/build/repo/node_modules/mongodb/lib/cmap/connection.js:202
5:30:39 PM:                 callback(new error_1.MongoServerError(document));
5:30:39 PM:                          ^
5:30:39 PM: MongoServerError: bad auth : authentication failed
5:30:39 PM:     at Connection.onMessage (/opt/build/repo/node_modules/mongodb/lib/cmap/connection.js:202:26)
5:30:39 PM:     at MessageStream.<anonymous> (/opt/build/repo/node_modules/mongodb/lib/cmap/connection.js:61:60)
5:30:39 PM:     at MessageStream.emit (node:events:517:28)
5:30:39 PM:     at processIncomingData (/opt/build/repo/node_modules/mongodb/lib/cmap/message_stream.js:124:16)
5:30:39 PM:     at MessageStream._write (/opt/build/repo/node_modules/mongodb/lib/cmap/message_stream.js:33:9)
5:30:39 PM:     at writeOrBuffer (node:internal/streams/writable:392:12)
5:30:39 PM:     at _write (node:internal/streams/writable:333:10)
5:30:39 PM:     at Writable.write (node:internal/streams/writable:337:10)
5:30:39 PM:     at TLSSocket.ondata (node:internal/streams/readable:809:22)
5:30:39 PM:     at TLSSocket.emit (node:events:517:28) {
5:30:39 PM:   ok: 0,
5:30:39 PM:   code: 8000,
5:30:39 PM:   codeName: "AtlasError",
5:30:39 PM:   connectionGeneration: 0,
5:30:39 PM:   [Symbol(errorLabels)]: Set(2) { "HandshakeError", "ResetPool" }
5:30:39 PM: }

我已经经历了一百万次不同的迭代和 Stackoverflow 回复。用户名很好,并且用户在 Mongo 上拥有管理员权限,密码已经过三次检查,并且如上所述,可以在本地使用。这完全是部署过程中出现的问题。帮忙吗?

mongodb
1个回答
0
投票

在部署过程中,我忘记考虑 .env 文件。在部署服务器设置中添加环境变量解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.