我已经建立了一个 mongodb Atlas 免费层集群。当我尝试使用节点 js 连接到它时,它会引发错误。我已经手动和选择当前将我的 IP 列入白名单。我也尝试将 +srv 添加到我的连接网址,但这只会导致更多错误。
这是我试图连接的节点 js 代码
const { MongoClient } = require("mongodb");
const url = "mongodb://user1:password1!@cluster0-shard-00-00-bc7dh.mongodb.net/test?retryWrites=true&w=majority&useNewUrlParser=true&useUnifiedTopology=true";
const client = new MongoClient(url);
async function run() {
try {
await client.connect();
console.log("Connected correctly to server");
} catch (err) {
console.log(err.stack);
}
finally {
await client.close();
}
}
run().catch(console.dir);
这是我得到的错误
MongoServerSelectionError: connection to 52.64.0.234:27017 closed at Timeout._onTimeout (C:\Users\YOUNG\node_modules\mongodb\lib\core\sdam\topology.js:430:30) at listOnTimeout (internal/timers.js:549:17) at processTimers (internal/timers.js:492:7)
有类似问题的人可以通过将他们的 IP 地址列入白名单来解决它,但它对我不起作用。可能是什么问题?
我尝试允许访问所有 ip,但错误仍然存在,当我将 uri 与 +srv 一起使用时,出现以下错误
MongoServerSelectionError: Authentication failed.
at Timeout._onTimeout (C:\Users\YOUNG\node_modules\mongodb\lib\core\sdam\topology.js:430:30)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
最佳答案
关于javascript - MongoDB atlas 连接失败,出现错误 MongoServerSelectionError : connection <monitor> to 52. 64.0.234:27017 closed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62342929/