mongodbmongodb-querymongodump

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.


Solution

  • 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.