mongodump vs mongoexport: which is better? [closed]
Asked Answered
M

4

19

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.

Median answered 3/9, 2020 at 8:37 Comment(0)
B
19

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.

Baras answered 3/9, 2020 at 9:37 Comment(2)
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 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.Radiotelegraphy
Oh, here's the warning. But no such warning for mongodb-4.4.Radiotelegraphy
C
4

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.

Crispin answered 5/9, 2020 at 16:0 Comment(2)
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?Countryman
@Countryman If you want to migrate to a relational database like Mysql, yes.Crispin
G
2

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

Georgiageorgian answered 11/10, 2022 at 17:49 Comment(0)
C
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.

Chronicles answered 17/6, 2022 at 6:40 Comment(4)
So which one to use?Countryman
Mongodump is the only choice if you need to choose between export and dump ...Chronicles
But what is the usecase of mongoexport then?Countryman
mongoexport can produce csv or json output for different transformations and post processing ...Chronicles

© 2022 - 2024 — McMap. All rights reserved.