简体   繁体   English

MongoDB拒绝使用NodeJS连接

[英]MongoDB refusing to connect using NodeJS

I have been struggling to connect to MongoDB for the past few hours now.在过去的几个小时里,我一直在努力连接到 MongoDB。 I have taken the code from the atlas documentation as seen below:我从 atlas 文档中获取了代码,如下所示:

const { MongoClient } = require('mongodb')
const url =
    'mongodb+srv://user:pass@mmmcluster.axapu.mongodb.net/appname?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)

I cannot for the life of me figure out why I keep getting the error below:我一生都无法弄清楚为什么我不断收到以下错误:

MongoServerSelectionError: connect ETIMEDOUT 157.241.16.152:27017
at Timeout._onTimeout (E:\Documents\Github\@test\node_modules\mongodb\lib\sdam\topology.js:306:38)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)

For the record:作为记录:

  1. All IP addresses are whitelisted on my database access list所有 IP 地址都在我的数据库访问列表中列入白名单
  2. I have turned off any firewalls that would be running over the internet, and whitelisted NodeJS on the windows firewall我已经关闭了任何将在 Internet 上运行的防火墙,并将 Windows 防火墙上的 NodeJS 列入白名单
  3. No spaces or brackets are have been included in my password or username我的密码或用户名中没有包含空格或括号
  4. The user has admin privileges on atlas用户在地图集上具有管理员权限

Any suggestions?有什么建议么? I am out of ideas here and I don't want to have to install Compass as a workaround since ideally, all methods of connection should work.我在这里没有想法,我不想安装 Compass 作为解决方法,因为理想情况下,所有连接方法都应该有效。

I think you should take a look here:我认为你应该看看这里:

const url =
    'mongodb+srv://user:pass@mmmcluster.axapu.mongodb.net/appname?retryWrites=true&w=majority&useNewUrlParser=true&useUnifiedTopology=true'

since there is this user and pass you might want to replace them with the actual username and password for the database.由于存在此userpass ,您可能希望将它们替换为数据库的实际用户名和密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM