Spa*_*ido 4 javascript mongodb mongodb-atlas
我已经建立了一个 mongodb Atlas 免费层集群。当我尝试使用节点 js 连接到它时,它会引发错误。我手动和选择当前都将我的 IP 列入白名单。我还尝试将 +srv 添加到我的连接 url 中,但这只会导致更多错误。
这是我试图连接的节点 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);Run Code Online (Sandbox Code Playgroud)
这是我得到的错误
MongoServerSelectionError: 到 52.64.0.234:27017 的连接在 Timeout._onTimeout (C:\Users\YOUNG\node_modules\mongodb\lib\core\sdam\topology.js:430:30) at listOnTimeout (internal/timers.js:549) 关闭:17) 在 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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5860 次 |
| 最近记录: |