我想从 MongoDB Atlas 导出一些数据。
如果我执行下面的命令,它会尝试连接localhost
并导出数据。
mongoexport --uri="mongodb+srv://<username>:<password>@name-of-project-x2lpw.mongodb.net/test" --collection users --out /tmp/testusers.json
Note:如果您从 Windows CMD 运行此命令,效果很好 https://stackoverflow.com/a/60214558/3710490
在研究问题并在用户的帮助下,一切似乎都指向 DNS 问题和相关问题resolv.conf
file.
低于原版/etc/resolv.conf
:
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 127.0.0.53
options edns0
search name.com
一开始就导致连接失败,如下所示:
但是,如果我根据建议将该地址更改为以下公共可用地址这个帖子 https://stackoverflow.com/questions/55660134/cant-connect-to-mongo-cloud-mongodb-database-in-golang-on-ubuntu to 1.1.1.1
连接成功,见下图:
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 1.1.1.1
options edns0
search name.com
结果连接成功,如下所示:
HOWEVER问题是,而不是显式连接到名称MongoDB
集群,它将连接到localhost
,这很奇怪,因为我成功地从真实连接中导出了我正在寻找的文件。意思是该机器已正确连接到数据库,但通过localhost
.
一切似乎都在引导,也根据这个来源 https://datawookie.netlify.com/blog/2018/10/dns-on-ubuntu-18.04/并且here https://unix.stackexchange.com/questions/174349/what-overwrites-etc-resolv-conf-on-every-boot连接时出现 DNS 问题MongoDB
通过终端导出集合。
现在,从最后一篇文章来看,出于多种原因,不建议手动更改此地址,因此在成功导出数据后立即使用DNS 1.1.1.1
我把它改回原来的样子DNS 127.0.0.53
。
但是,我认为这不应该是正确的行为,因为每次我需要导出数据时,我都必须不断地手动更改此地址。
这种奇怪行为的原因可能是什么?那么,如果不手动切换 DNS 地址,什么是长期解决方案呢?
感谢您为解决此问题指出了正确的方向。