【问题标题】:Can't connect to MongoDB Atlas (queryTxt ETIMEOUT)无法连接到 MongoDB Atlas (queryTxt ETIMEOUT)
【发布时间】:2019-10-13 12:48:03
【问题描述】:

我无法通过驱动程序、mongoshell 或 MongoDB 指南针连接到 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)

【问题讨论】:

  • 它对我有用,确实,当你配置时,你必须修改他们的连接选项卡提供的初始字符串......虽然够疯狂

标签: mongodb express mongodb-atlas


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我只是通过在下拉菜单中选择“2.2.12”的版本来解决这个问题。

    字符串是从

    mongodb+srv://username:password@cluster0.nbp7d.mongodb.net/myFirstDatabase?retryWrites=true&amp;w=majority

    mongodb://username:password@cluster0-shard-00-00.nbp7d.mongodb.net:27017,cluster0-shard-00-01.nbp7d.mongodb.net:27017,cluster0-shard-00-02.nbp7d.mongodb.net:27017/myFirstDatabase?ssl=true&amp;replicaSet=atlas-11wic9-shard-0&amp;authSource=admin&amp;retryWrites=true&amp;w=majority

    它在 2021 年 10 月 20 日为我工作。(Node js 和 Macbook 作为操作系统)

    请查看屏幕截图以获得更多帮助。

    【讨论】:

      【解决方案3】:

      欣赏 David buck 和 Abhay kumar:

      此问题与网络连接有关。 wifi 或其他有线连接没有获得完全权限,无法将您的系统传输或连接到 MongoDB 网络。解决方案:Mongodb中的IP白名单,需要在Ethernet-IP V4下系统的Public DNS中添加8.8.8.8。

      【讨论】:

      • 谢谢。解决了我的问题
      • 谢谢!非常有帮助!
      【解决方案4】:

      在研究了许多网站甚至联系了 MongoDB 支持之后,我正在写这个答案。

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

      【讨论】:

        【解决方案5】:

        我也遇到过类似的问题。

        我的字符串是:

        .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

        【讨论】:

          【解决方案6】:

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

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

          【讨论】:

            猜你喜欢
            • 2020-08-31
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-09-13
            • 2019-10-31
            • 2019-06-08
            • 2020-12-16
            • 2021-06-25
            相关资源
            最近更新 更多