Dump and Restore between version 3.6 and 5.0

I have a mongo replicaset on version 3.6.2. I want to upgrade it to 5.0. I do not want to perform the step by step upgrade process. Instead I want to create a new setup i.e replicaset in version 5.0.
I want to migrate the data to the new setup. I am planning to do the below steps:

  1. Take mongo dump using mongodump command in version 3.6.2
  2. Transfer the dump to the new instance
  3. Restore the dump in version 5.0 using mongorestore command

I tried this in the testing environment and it worked just fine. Can this cause any issues with the data. I could not find any info about thi in the mongo docs. Can I face issues later on because of the version difference?

1 Like

Hello and welcome to the community forum, @Ishrat Jahan!!

We do not suggest you to upgrade directly from 3.6 to 5.0 as there might be a great difference in the features and enhancements between the versions. Please refer to the following documentation here which explains the same.

Therefore, the recommended and tested in-place method is to upgrade the MongoDB version by upgrading sequentially. Hence, for you the upgrade sequence would be 3.6 → 4.0 → 4.2 → 4.4 → 5.0.

The reason why we suggest a step wise upgrade is because each major version is released with new features or enhancements of the legacy features. Hence to maintain the data integrity, the step wise upgrade is recommended. Please refer to the following documentation Upgrade to 5.0 to read more on the same.

In addition, we have a related discussion on a similar topic MongoDB community that you might want to take a look for further information/documentation.

Please do let us know if you have any concerns.

Thanks
Aasawari

2 Likes

Is there a 4.6 version of mongo ? I think we directly jump from 4.4 → 5 https://www.mongodb.com/docs/manual/release-notes/5.0-upgrade-replica-set/#upgrade-version-path

Thank you for pointing it out @Ishrat_Jahan.

It was MongoDB version 5.0 after 4.4. I would edit the post for future inconsistencies.

Thanks
Aasawari

2 Likes

@Aasawari Hi, I am using docker images of mongodb 4.4 in my server, now I want upgrade it to mongodb 7.0,
with docker could i upgrade to 7.0 directly? before that I will dump my data and restore it in mongodb 7.0.

Hi @shelton_zhang

Yes You would need to use the [mongodump](https://www.mongodb.com/docs/database-tools/mongodump/#mongodump) and [mongorestore](https://www.mongodb.com/docs/database-tools/mongorestore/) before you change the image from 4.4 to 7.0

You need to perform the steps below steps to do the upgrade.
If you have the mongo:4.4 running on a container named mongo4.4and has collections as

> db.example.find()
{ "_id" : ObjectId("66223ebb7d3bbdb1dfd8a3ae"), "name" : "a" }
{ "_id" : ObjectId("66223ebf7d3bbdb1dfd8a3af"), "name" : "b" }
>

Step1: Create the backup from the container mongo4.4

docker exec mongo4.4 mongodump --out /backups

Step 2: This backup is stored inside the container, so we need to copy the backup from the container to local

docker cp mongo4.4:/backups /<path to local>

Step 3: Copy this backup to the new container (say mongolatest running image mongo:latest)

docker cp /Users/aasawari.sahasrabuddhe/Downloads/backup/ mongolatest:/backups/

Step 4: Perform the restore on the latest container

aasawari.sahasrabuddhe@M-C02DV42LML85 Downloads % docker exec mongolatest mongorestore /backups

2024-04-19T10:20:01.209+0000	preparing collections to restore from
2024-04-19T10:20:01.209+0000	reading metadata for test.example from /backups/test/example.metadata.json
2024-04-19T10:20:01.219+0000	restoring test.example from /backups/test/example.bson
2024-04-19T10:20:01.234+0000	finished restoring test.example (2 documents, 0 failures)
2024-04-19T10:20:01.234+0000	no indexes to restore for collection test.example
2024-04-19T10:20:01.234+0000	2 document(s) restored successfully. 0 document(s) failed to restore.

Step 5: Validate if the data has been restored

aasawari.sahasrabuddhe@M-C02DV42LML85 Downloads % docker exec -it mongolatest mongosh
Current Mongosh Log ID:	66224568f7e58a3b14c934dc
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.4
Using MongoDB:		7.0.8
Using Mongosh:		2.2.4

For mongosh info see: https://docs.mongodb.com/mongodb-shell/
test> show dbs
admin    40.00 KiB
config  108.00 KiB
local    40.00 KiB
test      8.00 KiB
test> use test
already on db test
test> show collections
example
test> db.example.find()
[
  { _id: ObjectId('66223ebb7d3bbdb1dfd8a3ae'), name: 'a' },
  { _id: ObjectId('66223ebf7d3bbdb1dfd8a3af'), name: 'b' }
]

Please follow the above steps to perform the upgrade. Also the recommendation would be to perform rolling upgrade in order to avoid any failures.

Please don’t hesitate to reach out for any further questions.

Best Regards
Aasawari

1 Like