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

3

16

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

Nichollenicholls answered 15/6, 2017 at 8:51 Comment(0)
R
29

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
Reexamine answered 15/6, 2017 at 10:2 Comment(4)
This should be the actual process as you have suggested, but what will be possible problems if I use mongoexport and mongoimport :) if time and size is not the problem.Nichollenicholls
I have edited the answer to give more information, and a link to the MongoDB manual.Reexamine
solution : No easy way to upgrade :(Nichollenicholls
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?Wey
J
-2

From http://www.dba86.com/docs/mongo/2.4/core/import-export.html, mongoexport is supported from 2.4 version. Hence it should be the right tool for that. But still the document has warning message as well.

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.

Hope that helps!!!!

Jounce answered 15/6, 2017 at 10:12 Comment(0)
B
-5

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

Bhopal answered 15/6, 2017 at 8:56 Comment(2)
you have copied the exact text from this link dba.stackexchange.com/questions/107549/…, my use case is different, may be I have not conveyed the message correctly , my question is to which one should be right tool to export the database from older version and import into the newer version of mongoDB.Nichollenicholls
I think you'll find mongodump better & fasterBhopal

© 2022 - 2024 — McMap. All rights reserved.