2
votes

How can I export all my data in MongoDB, with a remote connection? I have my URI and haven't been able to find anything online using that.

mongoexport --uri <URI> -f <output_file>

This command works when I specify a collection, but I'm not sure how to export all collections using this.

2

2 Answers

4
votes

Mongoexport is used to export a collection of a specific db in JSON or CSV format.

You can not export all collections using mongoexport in a single command, you need to make individual request for each collection.

But if you want to take a backup of mongo and want to restore it on another node, then, you must use mongodump command.

As stated in MongoDB documentation,

WARNING

Avoid using mongoimport and mongoexport for full instance production backups.
They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON.
Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.

As already suggested, you can instead design a script, which will perform all the steps in order and will provide you with the desired results.

Thanks.

0
votes

For export all the collections you should user the mongdump command. Here how I use on my database:

mongodump -d<databaseName> --gzip --archive=<nomeArquivo.gz>