【发布时间】:2022-01-18 15:12:34
【问题描述】:
我希望有人可以帮助我,因为我对这个问题感到困惑 我认为我的代码没问题,但 Atlas 似乎拒绝了,所以我无法连接到 Atlas。连接如此简单。我从 nodemon.json 填充这些参数:
const {
MONGODB_ATLAS_USERNAME,
MONGODB_ATLAS_PASSWORD,
MONGODB_ATLAS_DBNAME
} = process.env
var mongoose = require('mongoose');
app.listen(PORT, () => {
console.info(`App is running! at http://localhost:${PORT}`)
})
mongoose.connect(`mongodb://${MONGODB_ATLAS_USERNAME}:${MONGODB_ATLAS_PASSWORD}@cluster0.lzjty.mongodb.net/${MONGODB_ATLAS_DBNAME}?retryWrites=true&w=majority&ssl=true`,{useNewUrlParser:true,useUnifiedTopology:true});
在 Atlas 上,我将我的 IP 列入白名单并允许所有 IP 连接 但是每次 npm 运行,总是返回:
App is running! at http://localhost:8080
[1] (node:2012) UnhandledPromiseRejectionWarning: 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吗?只是问,因为我以前见过人们这样做
-
当然,但是如果我使用非公共IP,它不应该已经能够使用0.0.0.0/0 连接吗?
标签: javascript node.js mongodb mongoose ip