Joh*_*ley 5 whitelist mongoose mongodb express mern
我看到类似的帖子,但没有一个能帮助我解决我的问题。
在学习了从头开始构建 MERN 应用程序的 Udemy 教程后,我陷入了 mongoose 连接的困境。
这是我的 index.js 代码:
const express = require("express");
const mongoose = require("mongoose");
const app = express();
app.use(express.json());
app.listen(5000, () => console.log("Server started on port 5000"));
app.use("/snippet", require("./routers/snippetRouter"));
mongoose.connect("mongodb+srv://snippetUser:_password_@
snippet-manager.sometext.mongodb.net/main?retryWrites=
true&w=majority", {
useNewUrlParser: true,
useUnifiedTopology: true
}, (err) => {
if (err) return console.log("error here " + err);
console.log("Connected to MongoDB");
});
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误:
Server started on port 5000
error here MongooseServerSelectionError: Could not connect to any
servers in your MongoDB Atlas cluster. One common reason is
that you're trying to access the database from an IP that isn't
whitelisted. Make sure your current IP address is on your Atlas
cluster's IP whitelist:
https://docs.atlas.mongodb.com/security-whitelist/
Run Code Online (Sandbox Code Playgroud)
如前所述,我看到与未列入白名单的 IP 相关的类似错误。
但是,在我的 mongoDB 帐户中,似乎我的 IP 已列入白名单:
在上面的屏幕截图中,空白部分是我的 IP 所在的位置(就在“包括您当前的 IP 地址”之前)。
既然我的 IP 列在那里,这是否意味着我的 IP 已被列入白名单?
如果没有,如何将我的 IP 列入白名单?
经过几天的挫折,我进入 Mongo Atlas,然后进入网络访问并将设置更改为“允许从任何地方访问”(如下所示0.0.0.0/0)。它删除了我的 IP 地址并将其更改为通配符 IP 地址。
这与我在 Udemy 上遵循的教程有所不同,但它确实有效,我终于可以继续课程的其余部分了。
| 归档时间: |
|
| 查看次数: |
16974 次 |
| 最近记录: |