如何导出MongoDB中的所有集合? [英] How to export all collections in MongoDB?
问题描述
我想通过以下命令导出MongoDB中的所有集合:
I want to export all collections in MongoDB by the command:
mongoexport -d dbname -o Mongo.json
结果是:
未指定收藏!
The result is:
No collection specified!
手册说,如果您不指定集合,则所有集合都将被导出.
但是,为什么这不起作用?
The manual says, if you don't specify a collection, all collections will be exported.
However, why doesn't this 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, use mongodump
, it's faster:
mongodump -d <database_name> -o <directory_backup>
并还原/导入"它(从directory_backup/dump/):
And to "restore/import" it (from directory_backup/dump/):
mongorestore -d <database_name> <directory_backup>
这样,您无需单独处理所有集合.只需指定数据库即可.
This way, you don't need to deal with all collections individually. Just specify the database.
请注意,我建议不要将mongodump
/mongorestore
用于大数据存储.这非常慢,一旦获得超过10/20GB的数据,它可能需要数小时才能恢复.
Note that 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屋!