简体   繁体   中英

Can't connect to MongoDB Atlas (queryTxt ETIMEOUT)

I can't connect to MongoDB Atlas either via driver, mongoshell, or MongoDB compass. Get to error: 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' }

I followed the guide from mongodb atlas (mongodb.cloud) on how to connect:

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();
});

with username and password replaced with real string value. I have strong feeling the cause is +srv part. When using mlab before, the connection is only mongodb:// (without the +srv)

Resolved the issue by contacting MongoDB support. The string URI should be changed to:

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

These are all the hostnames (primary and secondary) that you can see on the metrics tab of the cluster

Appreciate David buck and Abhay kumar:

This problem is related to the connection of network. The wifi or other wired connection is not getting full privileges' to transfer or connect your system with MongoDB network. Solution: IP White list in Mongodb and you need to add 8.8.8.8 in the Public DNS of your system under the Ethernet - IP V4.

I am writing this answer after researching on many websites and even contacted MongoDB support.

The problem is regarding the DNS server of your wifi. Kindly change your wifi or use the mobile hotspot and also whitelist the current connected IP on MongoDB, It will surely help, or Change the DNS of your wifi.

I've faced a similar problem.

My string was:

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

VS code terminal was shows this errors.

[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/>

This raised an error I've solved by making this change:

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

More details about can be found here

I simply solved this by selecting the version to "2.2.12" by the drop-down menu.

The string was changed from

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

To

"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&replicaSet=atlas-11wic9-shard-0&authSource=admin&retryWrites=true&w=majority"

It worked for me on 20 Oct 2021. (Node js and Macbook as OS)

Please check the screenshot for further help.

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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