无法连接到MongoDB Atlas(queryTxt ETIMEOUT)

t2a7ltrp  于 12个月前  发布在  Go
关注(0)|答案(6)|浏览(192)

我无法通过驱动程序、mongoshell或MongoDB Compass连接到MongoDB Atlas。返回错误:queryTxt ETIMEOUT

Error:  { Error: queryTxt ETIMEOUT clustermasjeed1-ekpfe.mongodb.net
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:197:19)
  errno: 'ETIMEOUT',
  code: 'ETIMEOUT',
  syscall: 'queryTxt',
  hostname: 'clustermasjeed1-ekpfe.mongodb.net' }

我遵循了mongodb atlas(mongodb.cloud)关于如何连接的指南:

const MongoClient = require(‘mongodb’).MongoClient;
const uri = "mongodb+srv://<username>:<password>@clustermasjeed1-ekpfe.mongodb.net/test?retryWrites=true";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
  const collection = client.db("test").collection("devices");
  // perform actions on the collection object
  client.close();
});

用户名和密码替换为真实的字符串值。我有强烈的感觉,原因是+srv部分。以前使用mlab时,连接只有mongodb://(没有+srv)

myzjeezk

myzjeezk1#

已通过联系MongoDB支持解决此问题。字符串URI应更改为:

mongodb://<username>:<password>@clustermasjeed1-shard-00-00-ekpfe.mongodb.net:27017,clustermasjeed1-shard-00-01-ekpfe.mongodb.net:27017,clustermasjeed1-shard-00-02-ekpfe.mongodb.net:27017/test?ssl=true&replicaSet=ClusterMasjeed1-shard-0&authSource=admin&retryWrites=true

这些是您可以在群集的Metrics选项卡上看到的所有主机名(主主机名和辅助主机名

emeijp43

emeijp432#

感谢大卫巴克和阿沛库马尔:
这个问题与网络连接有关。WiFi或其他有线连接没有获得完全权限来传输或连接您的系统与MongoDB网络。解决方案:IP白色名单在Mongodb和您需要添加8.8.8.8在您的系统的公共DNS下的以太网- IP V4。

ohfgkhjo

ohfgkhjo3#

我在许多网站上研究后写了这个答案,甚至联系了MongoDB支持。
这个问题是关于你的wifi的DNS服务器。请更改您的WiFi或使用移动的热点,并将MongoDB上当前连接的IP列入白名单,这肯定会有所帮助,或者更改您的WiFi的DNS.

e0bqpujr

e0bqpujr4#

我也遇到过类似的问题。
我的字符串是:

.connect(
    "mongoURI": "mongodb+srv://user:<password>@cluster0-lo1zs.mongodb.net/<dbname>?retryWrites=true&w=majority"
  )

VS代码终端显示此错误。

[0] Server started on port 9999<br/>
[0] queryTxt ETIMEOUT cluster0-lo1zs.mongodb.net<br/>
[1] Proxy error: Could not proxy request /api/profile/user/5f2be6e70fa40287805f6488 from localhost:3000
to http://localhost:9999/.<br/>
[1] See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNRESET).<br/>
[1]<br/>
[0] [nodemon] app crashed - waiting for file changes before starting...<br/>

这引起了一个错误,我通过做这个改变来解决:

.connect(
  "mongoURI": "mongodb://user:<password>@cluster0-shard-00-00-lo1zs.mongodb.net:27017,cluster0-shard-00-01-lo1zs.mongodb.net:27017,cluster0-shard-00-02-lo1zs.mongodb.net:27017/<dbname>?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true",
)

更多详情可以在here中找到

fslejnso

fslejnso5#

我简单地解决了这个问题,通过下拉菜单选择版本为“2.2.12”。
字符串已从
mongodb+srv://username: [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) /myFirstDatabase?retryWrites=true&w=majority

mongodb://username: [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) :27017,cluster0-shard-00-01.nbp7d.mongodb.net:27017,cluster0-shard-00-02.nbp7d.mongodb.net:27017/myFirstDatabase?ssl=true&replicaSet=atlas-11wic9-shard-0&authSource=admin&retryWrites=true&w=majority
它在2021年10月20日为我工作。(Node js和Macbook作为操作系统)
请查看屏幕截图以获得进一步帮助。

7dl7o3gd

7dl7o3gd6#

我遇到了同样的问题,并通过降级节点驱动程序的连接版本而不是使用节点v4来修复它尝试使用节点2.2。

相关问题