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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With