本文介绍了无法连接到MongoDB Atlas(queryTxt ETIMEOUT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我按照mongodb atlas(mongodb.cloud)的指南进行连接:

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

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

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)

推荐答案

通过联系MongoDB支持解决了该问题.字符串URI应该更改为:

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

这篇关于无法连接到MongoDB Atlas(queryTxt ETIMEOUT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 11:22