Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 249
forum.test17 Avatar asked Jun 15 '17 08:06

forum.test17


People also ask

Should I use Mongodump or Mongoexport?

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 .

What is difference between Mongoimport and Mongorestore?

One main difference between mongorestore and mongoimport is that mongorestore is insert only. This means that it will not overwrite a document in the database that already exists: mongorestore can create a new database or add data to an existing database.

Where is Mongodump used?

It is recommended to use the corresponding versions of mongodump and mongorestore in backup and restore operations. The mongodump command will overwrite the existing files within the given backup folder. The default location for backups is the dump/ folder.

What is Mongoimport and Mongoexport?

The mongoimport command is used to import your content from an extended JSON, CSV, or TSV export created by mongoexport. It also supports restoring or importing data from other third-party export tools. This command is of immense help when it comes to managing your MongoDB database.


1 Answers

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
like image 52
Vince Bowdren Avatar answered Oct 18 '22 01:10

Vince Bowdren