我正在使用 M0 GCP 实例。
我可以使用以下字符串连接到集群:
'mongodb+srv://my_user:my_pass@my_cluster-mbsnz.gcp.mongodb.net/db?retryWrites=true&w=majority'
我正在尝试使用另一个需要传递主机和端口的客户端,但无法连接。
我尝试 telnet 到端口 27017,但由于某种原因我无法直接连接到端口。
curl http://my_cluster-mbsnz.gcp.mongodb.net:27017
curl: (7) Failed to connect to my_cluster-mbsnz.gcp.mongodb.net port 27017: Connection timed out
或者
telnet my_cluster-mbsnz.gcp.mongodb.net 27017
Trying 185.82.212.199...
^C -> After a long time waiting
可能有什么问题?
最佳答案
+srv
url 使用 DNS 种子。在 map 集上,您可以单击进入集群,您应该能够看到主服务器和辅助服务器的 url,并使用这些 url 进行连接。您还应该可以使用 nslookup
使用该连接字符串的一部分来获取该信息,但通过 UI 查找 url 可能更简单。
https://docs.mongodb.com/manual/reference/connection-string/
In order to leverage the DNS seedlist, use a connection string prefix of mongodb+srv: rather than the standard mongodb:. The +srv indicates to the client that the hostname that follows corresponds to a DNS SRV record. The driver or mongo shell will then query the DNS for the record to determine which hosts are running the mongod instances.
关于mongodb - 无法在 Mongodb Atlas 端口上连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57240994/