6

我正在使用 mongoDB 来存储特定网站的数据。由于我们两个人都在工作,所以我们使用自己的电脑来完成这项工作。两台计算机都有一个数据库website_data和该数据库中的一个集合webpages。现在进行一些分析和绘制图表,我需要在一台 PC 中获取全部数据。如何结合两个数据库?我想写一个脚本,但我不知道如何连接到另一台计算机的数据库。是否有一些数据库文件可以直接复制到我的电脑上?

4

1 回答 1

19

You can do this with the command line tools mongodump and mongorestore.

Use mongodump --db [dbname] on the source computer to export all collections of the database into files which are stored in the directory dump/[collection].bson. Copy the files to the target computer and then use mongorestore --db [dbname] [collection].bson to import the generated files into the consolidated database. The contents will be appended to the existing collections as if you would use the insert command.

When you want to do it like a senior sysadmin: both command line tools have command line options to perform said operations on a remote system and you can pipe the output of mongodump right into mongorestore, so when you want to show off you could do it with one console command from a remote system. But when this is a one time thing and command line trickery is not your passion, rather stick to files.

于 2015-09-17T08:27:49.023 回答