-
Notifications
You must be signed in to change notification settings - Fork 5
Update MongoDB to 8.x
A practical guide for upgrading MongoDB from 4.4 to 8.x using Docker Compose, including all the gotchas you'll likely run into.
You cannot jump directly from 4.4 to 8.x. MongoDB requires stepping through each major version sequentially, setting the Feature Compatibility Version (FCV) at each step before moving on.
Required upgrade path:
4.4 → 5.0 → 6.0 → 7.0 → 8.0 → 8.2
docker exec <container> mongodump --out /dump
docker cp <container>:/dump ./mongo-backupdocker exec <container> mongo --eval "db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })"It should report 4.4.
MongoDB 5.0+ requires AVX CPU support. Check if your system has it:
grep avx /proc/cpuinfo | head -1If this returns nothing, see the AVX support section below before continuing.
MongoDB 5.0 and above require AVX instructions. If your CPU doesn't expose AVX, the container will fail to start.
This is the most common cause. By default, hypervisors present a generic CPU to guests that doesn't include AVX, even if the underlying hardware supports it.
Fix for Proxmox:
- Shut down the VM from Proxmox (not just the guest OS)
- Go to your VM → Hardware → Processors
- Change the CPU Type from
kvm64to one of:-
host— passes through all host CPU features; best performance but prevents live migration between nodes with different CPUs -
x86-64-v3— includes AVX/AVX2, works on most hardware since ~2013, safer for multi-node setups
-
- Start the VM and verify:
grep avx /proc/cpuinfo | head -1You should now see a line of CPU flags including avx.
If you're genuinely on old hardware without AVX, you cannot run MongoDB 5.0+. Your options are:
- Upgrade the hardware
- Use a managed service like MongoDB Atlas
- Consider a MongoDB-compatible alternative like FerretDB
The pattern for each version step is:
- Set FCV on the currently running version
- Update the image tag in your compose file
- Bring the container back up
- Verify it started
Note: MongoDB 4.4 uses the legacy
mongoshell. From 5.0 onwards, usemongosh.
# Set FCV on running 4.4 instance
docker exec <container> mongo --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "4.4" })'Update your docker-compose.yml:
image: docker.io/library/mongo:5.0docker compose down
docker compose up -d
# Set FCV to 5.0
docker exec <container> mongosh --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "5.0" })'# Set FCV on running 5.0 instance
docker exec <container> mongosh --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "5.0" })'Update your docker-compose.yml:
image: docker.io/library/mongo:6.0docker compose down
docker compose up -d
docker exec <container> mongosh --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "6.0" })'docker exec <container> mongosh --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "6.0" })'Update your docker-compose.yml:
image: docker.io/library/mongo:7.0docker compose down
docker compose up -d
docker exec <container> mongosh --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "7.0" })'Note: From 7.0 onwards, MongoDB requires a
confirm: trueflag when setting FCV because the upgrade is irreversible without support assistance.
docker exec <container> mongosh --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "7.0", confirm: true })'Update your docker-compose.yml:
image: docker.io/library/mongo:8.0docker compose down
docker compose up -d
docker exec <container> mongosh --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "8.0", confirm: true })'# Already on 8.0 with FCV set aboveUpdate your docker-compose.yml:
image: docker.io/library/mongo:8.2docker compose down
docker compose up -d
docker exec <container> mongosh --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "8.2", confirm: true })'You're done! 🎉
If you have a healthcheck in your compose file, note that the mongo shell was removed in MongoDB 6.0. Update your healthcheck to use mongosh:
healthcheck:
test: ["CMD-SHELL", "mongosh --eval 'db.runCommand({ping:1}).ok' --quiet"]
interval: 15s
timeout: 30s
retries: 5
start_period: 35sThis usually means FCV mismatch — you skipped setting the FCV before jumping to the next version. Drop back one version, set the FCV, then try again.
docker inspect <container> | grep ExitCodeCheck the logs:
docker logs <container>Look for a line like:
Invalid featureCompatibilityVersion value '7.0'. Expected one of the following versions: '8.2', '8.1', '8.0'
This tells you exactly what went wrong and what version the FCV needs to be at.
If your logging driver is set to journald, syslog, or none, docker logs won't work. Temporarily change it in your compose file for debugging:
logging:
driver: json-fileRemember to change it back afterwards.
Try journald directly:
journalctl -u docker --since "10 minutes ago"- Never skip versions — jumping from 4.4 to 6.0+ will prevent MongoDB from opening your data files
- Always set FCV before upgrading — this is the most common mistake
-
mongoshell is gone from 6.0+ — usemongoshinstead confirm: trueis required from the 7.0 → 8.0 FCV step onwards-
Pin your image tag — use
mongo:8.2instead ofmongo:8so adocker compose pulldoesn't silently upgrade you to a future minor version