所以我绞尽脑汁想知道为什么我所有的MongoDB用户的身份验证都失败了。一切正常,直到我删除了一个用户,从那以后,我所有的用户都被拒绝了。我正在使用Altas,我已经将我的用户设置为dbAdmin,并赋予了所有权利,双重检查使我在pw中没有拼写错误,我设置了IP地址,确保我复制了正确的url。。我正在尝试连接Nodejs应用程序,这是我的代码:
const express = require("express");
const mongoose = require("mongoose");
const app = express();
// Connect to DB
const mongoURI =
"mongodb+srv://MyUserName:<MyPassword>@cluster0.lbb8n.mongodb.net/<DbImUsing>?retryWrites=true&w=majority";
mongoose.connect(mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
// Route
app.set("view engine", "ejs");
app.get("/", (req, res) => {
res.render("index");
});
// Endpoint
app.post("/shortUrls", (req, res) => {});
app.listen(process.env.PORT || 5000);
我收到的错误消息是:
(node:5058) UnhandledPromiseRejectionWarning: MongoError: bad auth : Authentication failed.
at MessageStream.messageHandler (/Users/fridavbg/Desktop/MovingWorlds/urlShortv2/node_modules/mongodb/lib/cmap/connection.js:268:20)
at MessageStream.emit (events.js:315:20)
at processIncomingData (/Users/fridavbg/Desktop/MovingWorlds/urlShortv2/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/Users/fridavbg/Desktop/MovingWorlds/urlShortv2/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at writeOrBuffer (_stream_writable.js:352:12)
at MessageStream.Writable.write (_stream_writable.js:303:10)
at TLSSocket.ondata (_stream_readable.js:719:22)
at TLSSocket.emit (events.js:315:20)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:284:9)
at TLSSocket.Readable.push (_stream_readable.js:223:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5058) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5058) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
发布于 2021-01-16 16:45:30
查看服务器日志以了解身份验证失败的原因。
如果你在免费或共享层(m0/m2/m5),日志不可用,你必须猜测。
由于您使用的是SRV URI,因此请尝试显式指定身份验证源:
"mongodb+srv://MyUserName:<MyPassword>@cluster0.lbb8n.mongodb.net/<DbImUsing>?retryWrites=true&w=majority&authSource=admin"
发布于 2021-01-16 12:04:12
尝试扩展连接
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
还要检查MongoDB中的网络访问。
添加您当前的IP地址。
https://stackoverflow.com/questions/65749358
复制相似问题