15

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.

Asef Pourmasoomi
  • 464
  • 1
  • 3
  • 17

4 Answers4

15

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.

Gibbs
  • 21,904
  • 13
  • 74
  • 138
  • Can't see the "Avoid using mongoimport..." part in the documentation these days. Also, your quotes doesn't say anything about "large data." Moreover, [here](https://docs.mongodb.com/manual/core/backups/#back-up-with-mongodump) the documentation says: "mongodump and mongorestore are simple and efficient tools for backing up and restoring small MongoDB deployments, but are not ideal for capturing backups of larger systems." But well, having that said, `mongodump` is probably generally preferable. – x-yuri Apr 26 '21 at 16:55
  • Oh, [here](https://docs.mongodb.com/v4.2/reference/program/mongoexport/#type-fidelity)'s the warning. But no such warning for [mongodb-4.4](https://docs.mongodb.com/database-tools/mongoexport/). – x-yuri Apr 26 '21 at 16:59
3

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.

Rahman
  • 410
  • 6
  • 26
  • So mongoexport can give you CSV output which could be better format for heterogenous migration to another database system (for example SQL)? If so, then that should be prefered right? – milanHrabos Aug 18 '22 at 11:42
  • @milanHrabos If you want to migrate to a relational database like Mysql, yes. – Rahman Aug 22 '22 at 05:04
0

The best answer to this question here is to use file system snapshots as for large clusters both mongoexport and mongodump can take some significant time.

R2D2
  • 9,410
  • 2
  • 12
  • 28
0

Mongodump is preferable ,if whole database or collection needs to be backedup. use Mongorestore to restore the backed up data, its very fast , stores in Bson mongoexport is preferable for backing up the subset of the documents in a collection Slow compared to mongodump . the data can be stored in either csv or Json ,as per the type specified in the Command. use Mongoimport to import the backed up data , to a specific collection with in a database .Hope this may help.

vishwanath

vishu
  • 21
  • 1