I was faced with this challenge when a workload in my homelab was using a very dated MongoDB 3.6 database, and updating it the workload, its now possible to run MongoDB 7.
I was not able to easily find any resources online that described this kind of upgrade so I decided to write my own.
The upgrade path for MongoDB is complex, requiring the sequence:
3.6 → 4.0
4.0 → 4.2
4.2 → 4.4
4.4 → 5.0
5.0 → 6.0
6.0 → 7.0
Additionally the package installation on Debian, particularly for the EOL versions is complex – so I opted to use Docker images from MongoDB for each version. In my case I performed this on a Debian environment under WSL.
At the start and the end I transferred the MongoDB database to and from the folder ~/db
With this process there were some differences with version 6 and 7 – but it was fairly straightforward.
I first began the migration by retrieving the docker images
docker pull mongo:3.6
docker pull mongo:4.0
docker pull mongo:4.2
docker pull mongo:4.4
docker pull mongo:5.0
docker pull mongo:6.0
docker pull mongo:7.0Version 3.6
I felt it important to validate setFeatureCompatibilityVersion was set to 3.6 and confirm the Docker image is able to read my database
I started the container:
docker run -d \
--name mongo36 \
-v ~/db:/data/db \
-p 27017:27017 \
mongo:3.6I spawned a mongo shell:
docker exec -it mongo36 mongoI validated setFeatureCompatibilityVersion:
use admin
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
// If needed, set it to 3.6
db.adminCommand({ setFeatureCompatibilityVersion: "3.6" })
// exit the Mongo shell
exitI stopped the container:
docker stop mongo36
docker rm mongo36Version 4.0
I started the container:
docker run -d \
--name mongo40 \
-v ~/db:/data/db \
-p 27017:27017 \
mongo:4.0I spawned a mongo shell:
docker exec -it mongo40 mongoI set the new setFeatureCompatibilityVersion:
use admin
// Confirm current FCV
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
// Now set to 4.0
db.adminCommand({ setFeatureCompatibilityVersion: "4.0" })
exitI stopped the container:
docker stop mongo40
docker rm mongo40Version 4.2
I started the container:
docker run -d \
--name mongo42 \
-v ~/db:/data/db \
-p 27017:27017 \
mongo:4.2I spawned a mongo shell:
docker exec -it mongo42 mongoI set the new setFeatureCompatibilityVersion:
use admin
// Confirm current FCV
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
// Now set to 4.2
db.adminCommand({ setFeatureCompatibilityVersion: "4.2" })
exitI stopped the container:
docker stop mongo42
docker rm mongo42Version 4.4
I started the container:
docker run -d \
--name mongo44 \
-v ~/db:/data/db \
-p 27017:27017 \
mongo:4.4I spawned a mongo shell:
docker exec -it mongo44 mongoI set the new setFeatureCompatibilityVersion:
use admin
// Confirm current FCV
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
// Now set to 4.4
db.adminCommand({ setFeatureCompatibilityVersion: "4.4" })
exitI stopped the container:
docker stop mongo44
docker rm mongo44Version 5.0
I started the container:
docker run -d \
--name mongo50 \
-v ~/db:/data/db \
-p 27017:27017 \
mongo:5.0I spawned a mongo shell:
docker exec -it mongo50 mongoI set the new setFeatureCompatibilityVersion:
use admin
// Confirm current FCV
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
// Now set to 5.0
db.adminCommand({ setFeatureCompatibilityVersion: "5.0" })
exitI stopped the container:
docker stop mongo50
docker rm mongo50Version 6.0
I started the container:
docker run -d \
--name mongo60 \
-v ~/db:/data/db \
-p 27017:27017 \
mongo:6.0I spawned a mongo shell:
docker exec -it mongo60 mongoshI set the new setFeatureCompatibilityVersion:
use admin
// Confirm current FCV
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
// Now set to 6.0
db.adminCommand({ setFeatureCompatibilityVersion: "6.0" })
exitI stopped the container:
docker stop mongo60
docker rm mongo60Version 7.0
I started the container:
docker run -d \
--name mongo70 \
-v ~/db:/data/db \
-p 27017:27017 \
mongo:7.0I spawned a mongo shell:
docker exec -it mongo70 mongoshI set the new setFeatureCompatibilityVersion:
use admin
// Confirm current FCV
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
// Now set to 7.0
db.adminCommand({ setFeatureCompatibilityVersion: "7.0", confirm: true })
exitI stopped the container:
docker stop mongo70
docker rm mongo70
In the end, did the migration work? Or was there a problem with the data?
Worked perfectly fine