database 如何将 mongodb 数据库传输到另一台看不到第一个数据库的机器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7232461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I transfer a mongodb database to another machine that cannot see the first one
提问by Zugwalt
I have a server that is having trouble talking to the outside world. I would like to get its mongodb contents to another server--but since the servers cannot talk to eachother db.copyDatabase()won't do.
我有一台服务器,无法与外界通话。我想将其 mongodb 内容发送到另一台服务器——但由于服务器无法相互交谈 db.copyDatabase()不会这样做。
Is there something like mysqldump where I could dump the db into a binary file, scp that somewhere, and then use that to populate another mongodb server?
有没有像 mysqldump 这样的东西,我可以将数据库转储到一个二进制文件中,在某处 scp ,然后用它来填充另一个 mongodb 服务器?
采纳答案by Amir Raminfar
Use the mongodump and mongorestorecommands.
mongodump --db test --collection collection
mongorestore --collection collection --db test dump/
You can also gzip. The documentation has more examples.
你也可以gzip。该文档有更多示例。
回答by Tom G
If you're using Ubuntu/Linux, run the following commands. First, mongodumpon the origin server:
如果您使用的是 Ubuntu/Linux,请运行以下命令。首先,mongodump在源服务器上:
mongodump --db DataBaseName
Copy the generated dump/DataBaseNamefolder to the new machine. Then, import using mongorestore:
将生成的dump/DataBaseName文件夹复制到新机器上。然后,使用导入mongorestore:
mongorestore --db DataBaseName /path/to/DataBaseName
Note that /path/to/DataBaseNameshould be a directory filled with .json and .bson representations of your data.
请注意,这/path/to/DataBaseName应该是一个包含数据的 .json 和 .bson 表示的目录。
回答by Kajal Chauhan
If you want to transfer database to another system, then you must use the following commands.
如果要将数据库转移到另一个系统,则必须使用以下命令。
First dump the database to the output directory:
首先将数据库转储到输出目录:
mongodump --db DatabaseName -o ./DirectoryName
then copy that directory and put it into your machine and issue this command:
然后复制该目录并将其放入您的机器并发出以下命令:
mongorestore --db DBName ./DirectoryName

