无法连接到mongodb地图集

时间:2019-05-28 03:27:16

标签: mongodb express mongodb-atlas

无法通过驱动程序,mongoshell或mongodb指南针连接到mongodb地图集。错误提示: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)

4 个答案:

答案 0 :(得分:1)

我遇到了类似的问题。

我的字符串是:

.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",
)

有关更多详细信息,请参见enter image description here

答案 1 :(得分:1)

在许多网站上进行研究后,甚至与MongoDB支持人员联系后,我正在写此答案。

问题与您的wifi的DNS服务器有关。请更改您的wifi或使用移动热点,并将白名单上的当前连接IP列入白名单,这肯定会有所帮助,或者更改您的wifi的DNS。

答案 2 :(得分:1)

欣赏David buck和Abhay kumar:

此问题与网络连接有关。 wifi或其他有线连接未获得将系统与MongoDB网络传输或连接的完整特权。解决方案:Mongodb中的IP白名单,您需要在以太网-IP V4下的系统的公共DNS中添加8.8.8.8。

答案 3 :(得分:0)

通过联系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

这些是您可以在集群的“指标”选项卡上看到的所有主机名(主要和次要)

相关问题