Backup with mongoexport or mongodump?

  1. (sorry, dunno)

  2. --query will select or exclude entire documents, not fields.

It would be a good idea though :

--query '{datetime:{$gt:ISODate("2014-01-01T00:00:00.000Z")}},{_id:0,name:1,address:1,interests:1}'* )
  1. Mongodump uses bson file structure and preserves the data types. Mongoexport will lose data type of the values. Such as NumberLong("1431677405876") would be converted to just 1431677405876. That's why mongodump is advised if you need to import back to MongoDB.

As an answer to your first question, both tools (by default) will just walk the _id index to fetch the data and then write it out to disk. So, yes, both tools will similarly impact your working set which is why I would generally recommend running them against a secondary (preferably a hidden secondary if possible). I'll echo Stennie in the comments here and recommend other backup methods if you are dealing with large amounts of data.

For the second question, I assume you are looking for a mongodump equivalent of the --fields option from mongoexport to only dump out specific fields. The query option can be used to filter results, but it cannot be used with a projection (to select the fields returned) - this is a feature request that is being tracked in TOOLS-28 but is not yet scheduled. As Stennie also mentioned, the other option here is to write a custom exporter that fits your needs (and again, I would still recommend running it against a secondary to protect your working set).

Tags:

Backup

Mongodb