Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export all collections in MongoDB?

Tags:

export

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

My MongoDB version is 2.0.6.

like image 835
aboutstudy Avatar asked Jun 29 '12 03:06

aboutstudy


People also ask

How do I export a MongoDB collection to CSV?

Export MongoDB to CSV (e.g. Excel) Open the Export Wizard and select your export source. This screen only appears if you haven't chosen an item in the Connection Tree, run a previous query, or selected specific documents. Next, choose CSV as the export format then click Next.


1 Answers

For lazy people, use mongodump, it's faster:

mongodump -d <database_name> -o <directory_backup> 

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.

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.

like image 152
Mentor Reka Avatar answered Oct 05 '22 13:10

Mentor Reka