Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

express - mongoDB whitelist IP

I am seeing similar posts, however none are helping me solve my problem.

Following a Udemy tutorial that builds a MERN application from scratch, I got stuck on the mongoose connection.

Here is my index.js code:

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");
});

Here is the error I am getting:

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/ 

As stated, I am seeing similar errors relating to an IP that isn't whitelisted.

However, in my mongoDB account, it seems that my IP is already whitelisted:

enter image description here

In the screenshot above, the blank part is where my IP is located (right before it says "includes your current IP address").

Since my IP is listed there, does that not mean my IP is whitelisted?

If not, how do I whitelist my IP?

question from:https://stackoverflow.com/questions/65948083/mongodb-whitelist-ip

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

After a couple of days of frustration, I went into Mongo Atlas, then into Network Access and changed the setting to "allow access from anywhere". It removed my IP address and changed it to a universal IP address.

This was a deviation from the tutorial I am following on Udemy, but it did work, and I can finally proceed with the rest of the course.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...