微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

mongoDB白名单IP

如何解决mongoDB白名单IP

我看到了类似的帖子,但没有一个能帮助我解决问题。

按照从头开始构建 MERN 应用程序的 Udemy 教程,我卡在猫鼬连接上。

这是我的 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");
});

这是我得到的错误

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/ 

如上所述,我看到与未列入白名单的 IP 相关的类似错误

然而,在我的mongoDB账户中,我的IP似乎已经被列入白名单:

enter image description here

在上面的屏幕截图中,空白部分是我的 IP 所在的位置(就在它说“包括您当前的 IP 地址”之前)。

既然我的 IP 列在那里,那不就意味着我的 IP 被列入白名单了吗?

如果没有,我如何将我的 IP 列入白名单?

解决方法

经过几天的挫折后,我进入了 Mongo Atlas,然后进入了网络访问,并将设置更改为“允许从任何地方访问”。它删除了我的 IP 地址并将其更改为通用 IP 地址。

这与我在 Udemy 上遵循的教程有所不同,但它确实有效,我终于可以继续本课程的其余部分了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。