Which one is the preferred choice Mongodump VS Mongoexport for upgrading mongoDB database?

forum.test17 picture forum.test17 · Jun 15, 2017 · Viewed 11.4k times · Source

My customer uses mongoDB 2.4 and as there are some limitations with this version, we have give them the option to upgrade to Latest stable mongoDB 3.4.5.

Initial testing of using mongodump in MongoDB 2.4 and mongorestore in Mongodb 3.4.5 worked fine as I can see all the collections imported.

From the documentation mongorestore it was not mentioned anywhere that it can restore the dumps from older versions of mongoDB.

As we cannot use the mongorestore , Can I use "mongoexport" to export the data in csv/json format of older mongoDB 2.4 , and import into newer version of mongoDB 3.4 ?

What are the possible problems of using "mongoexport/mongoimport" instead of "mongodump" to upgrade to newer version of mongoDB 3.4 ?

NOTE: I will remove the older version of mongoDB completely and will install the newer version of mongoDB

Answer

Vince Bowdren picture Vince Bowdren · Jun 15, 2017

Mongodump and Mongorestore are better because:

  1. They run faster
  2. They preserve some data formats better than mongoexport and mongoimport, because the data is not translated from BSON into JSON and back.

As described in the MongoDB Docs on MongoImport:

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

In addition, be very careful about the upgrade using mongorestore; just because the data is restored as it was previously, this does not mean that the new version of MongoDB can work with it. For example there were a sequence of changes to the authorisation model after v2.4 which means that you must first upgrade to v2.6, and only then to v3.0. There are similar structural changes at each major version, so it is recommended that you upgrade stepwise, one major version at a time i.e.

  1. v2.4 -> v2.6
  2. v2.6 -> v3.0
  3. v3.0 -> v3.2
  4. v3.2 -> v3.4