如何导出MongoDB中的所有集合? [英] How to export all collection in MongoDB?
问题描述
我想通过命令导出MongoDB中的所有集合:
I want to export all collection in MongoDB by the command:
mongoexport -d dbname -o Mongo.json
结果是:
未指定集合!
The result is:
No collection specified!
手册说,如果没有指定,所有的集合都将被导出。
但是,为什么这不能做正确的工作?
The manual say, if you do not specify a , all collections will be exported.
However, why this can't do the right work?
http://docs.mongodb.org/manual/reference/mongoexport/#cmdoption-mongoexport-collection
我的MongoDB版本是2.0.6
My MongoDB version is 2.0.6
推荐答案
对于像我这样的懒惰的人,我使用mongodump更快:
For lazy people like me, i use mongodump it's faster:
mongodump -d <database_name> -o <directory_backup>
为了恢复/导入,我使用(来自directory_backup / dump /): p>
And to "restore/import" that, i used (from directory_backup/dump/):
mongorestore -d <database_name> <directory_backup>
使用此解决方案,您不需要每个所有的集合并逐个导出。只需指定数据库。
我建议不要使用mongodump / mongorestore进行大数据存储。这是非常慢的,一旦你超过10 / 20GB的数据,可能需要几个小时才能恢复。
With this solution, you don't need to each all collections and export one by one. Just specify the database. I would recommend against using mongodump/mongorestore for big data storages. It is very slow and once you get past 10/20GB of data it can take hours to restore.
这篇关于如何导出MongoDB中的所有集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!