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