从本地迁移到MongoDb Atlas

我正在尝试将本地MongoDB迁移到Atlas。

我设法用localhost运行mongodump命令,并且可以在./dump/data.bson中看到文件

但是,当我现在想要将此转储恢复到Atlas时,出现“失败:连接到数据库服务器时出错:没有可访问的服务器”。

这很奇怪,因为我可以使用以下命令从mongo shell(v4.0)连接到Atlas:“ mongo mongodb + srv://cluster0-xxxxxx.mongodb.net/test --username Bob”提示输入密码并连接正常。

这是mongorestore命令,它给了我上面的连接错误:

mongorestore --ssl --host mongodb+srv://cluster0-xxxxx.mongodb.net/test --username Bob --authenticationDatabase admin --dir dump/data --password Test123

感谢您的帮助。

chenhao988325 回答:从本地迁移到MongoDb Atlas

好,所以我找到了解决方法。

您需要将集合导出为JSON(可以通过Compass->集合(下拉菜单)->导出集合)。

然后,您需要使用mongoimport(而不是mongorestore)。此处的完整信息:https://docs.atlas.mongodb.com/import/mongoimport/

我想mongorestore无法正常工作,因为我的本地服务器是一个独立的数据库,而Atlas是一个副本集...尽管我尚未确认。

,

尝试将连接字符串的开头从mongodb+srv://更改为mongodb://

,

如果您需要上传.BSON,则需要使用mongo restore, 这样

enter image description here

您需要在路径转储之前写上de命令/ 例如,如果系统折叠是

example / example / mydata => hi.bson再见.bson 您应该创建“转储”文件

像这样 example / example / dump / mydata => hi.bson bye.bson

并在example / example /上运行命令,因为mongo将搜索“ / dump”

您需要指定为什么在命令末尾带有--db标志的BD

,

使用

mongorestore --ssl --host <host> --authenticationDatabase admin --dir="<dumpDirectory>" -u <adminUserName> --password <password>

<host>: get from mongo atlas dashboard (click on the cluster name) ex: cluster0-shard-00-00-cbei2.mongodb.net:27017 
<dumpDirectory>: The folder where database is dumped using mongodump
<adminUserName>: admin User for that database
<password>: admin associated password
,

在地图集站点上有明确的文档。当您查看集群时,将有一个 Cmd Line Tools 选项卡。

这是步骤。

  1. 在没有选项的情况下在本地系统上运行 mongodump

  2. 从同一个系统运行:mongorestore --uri mongodb+srv://<USER>:<PASSWORD>@thename.mongo.gives.your.cluster.mongodb.net

您可能需要打开 atlas 防火墙以允许来自本地计算机 IP 的连接(如果您尚未打开)。

,

您可以像这样轻松导入/导出:

mongoimport --uri mongodb+srv://<USERNAME>:<PASSWORD>@your-cluster.mongodb.net/<DATABASE_NAME> --collection <COLLECTION> --type <FILETYPE> --file <FILENAME>

mongoexport --uri mongodb+srv://<USERNAME>:<PASSWORD>@your-cluster.mongodb.net/<DATABASE_NAME> --collection <COLLECTION> --type <FILETYPE> --out <FILENAME>

您也可以在 Your Cluster > Cmd Line Tools

上找到这些
本文链接:https://www.f2er.com/2997992.html

大家都在问