Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodump vs mongoexport: which is better?

I want to export very large collections and import them into another database in another server. I found there are at least two ways: mongoexport and mongodump.

I searched previous posts about this issue, however I did not find a complete comparison/benchmark about the speed of exporting and size of export file using these two ways! I will be so thankful if there is any experience to share.

like image 573
Asef Pourmasoomi Avatar asked Sep 03 '20 08:09

Asef Pourmasoomi


People also ask

Where is Mongodump used?

The mongodump is a utility for creating database backups. The utility can be used for creating binary export of the database contents. Mongodump can export data from both mongod and mongos instances, allowing you to create backups from: A standalone, replica set.

What is Mongoimport and Mongoexport?

The mongoimport tool imports content from an Extended JSON, CSV, or TSV export created by mongoexport , or potentially, another third-party export tool. Run mongoimport from the system command line, not the mongo shell. Tip. See also: mongoexport which provides the corresponding structured data export capability.

Does Mongodump lock the database?

Mongdump does not lock the db. It means other read and write operations will continue normally. Actually, both mongodump and mongorestore are non-blocking. So if you want to mongodump mongorestore a db then its your responsibility to make sure that it is really a desired snapshot backup/restore.


Video Answer


2 Answers

As mentioned in the latest documentation

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 you need to restore large data, prefer dump.

mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance.

mongodump is a utility for creating a binary export of the contents of a database. mongodump can export data from either mongod or mongos instances; i.e. can export data from standalone, replica set, and sharded cluster deployments.

like image 141
Gibbs Avatar answered Sep 20 '22 00:09

Gibbs


One of the important differences is that mongodump is faster than mongoexport for backup purposes. Mongodump store data as a binary, whereas, mongoexport store data as a JSON or CSV.

like image 30
Rahman Avatar answered Sep 20 '22 00:09

Rahman