sai
sai

Reputation: 79

Migration of MongoDB data to a newer version using mongodump/mongoexport

Current version of MongoDB I am using is 4.0. I want to upgrade it to 6.0. According to the official documentation, it is not possible to jump from 4.0 to 6.0. The following order must be followed: 4.0 -> 4.2 -> 4.4 -> 5.0 -> 6.0.

But this is a long process. Have to do testing 4 times, once after each upgrade.

So, I thought of creating new MongoDB 6.0 instance, and migrate all the data from the old instance to new instance.

I came across the following utilities: mongodump and mongoexport.

Issue with mongoexport: (found it here)

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.

Issue with mongodump: (found it here)

using mongorestore to restore a 4.0 dump to 4.4 is not supported.
The reason for this is that collection options, index options,
and oplog entry formats can change between versions.
We do not test dump/restore from different versions so we cannot
guarantee that it will work correctly in all cases.
Because of this, it is not officially supported.

Are there workarounds for any of the above mentioned issues?

I am okay with MongoDB downtime during migration. I want to transfer just the data. Don't want to transfer things like indexes, which can be built in the new instance after the transfer is complete.

Is this possible? Are there any flaws in this approach? Should I just stick to 4.0 -> 4.2 -> 4.4 -> 5.0 -> 6.0?

Thanks!

Upvotes: 3

Views: 2547

Answers (1)

Eugene
Eugene

Reputation: 277

Ok, I'm in the same place, having the v4 version and need to upgrade. Given that there's no easy way to have an upgrade path that doesn't involve porting the data I'm gonna implement a new general approch, I'll create a console application to extrapolate/import all the DB data in JSON, each Collection in its own file.json.

Pros: I can port that data to any DB in the future, no longer limited to the DB version nor type, free to switch in the future when the needs change.

Cons: Backup files management and extra development time/effort.

Upvotes: 0

Related Questions