Upgrading Mongdb from 3.6.8 to 4.0 when installed with Apt - Ubuntu 20.04 focal

Hello, I am needing to upgrade Mongodb (which was installed using apt) from 3.6.8 - ubuntu default - to version 4.0 or higher.

In checking the v4.0 manual (Install MongoDB Community Edition on Ubuntu — MongoDB Manual) only 18.04 bionic is supported. Also according to the manual “If you installed MongoDB from the MongoDB apt, yum, dnf, or zypper repositories, you should upgrade to 4.0 using your package manager.”(https://www.mongodb.com/docs/manual/release-notes/4.0-upgrade-replica-set/).

If version 3.6 needs to be upgraded to 4.0 (to then be upgraded beyond that as version 4.4 is supported on 20.04) and should be done using the package manager but version 4.0 isn’t supported on 20.04 can someone point me to the procedure I should follow? Thanks.

Any ideas on this? Can anyone share a link or experience on what they did?

Really interested in anyone’s experience relating to this.

I’m currently running into the same issue. We have a Graylog environment running on Ubuntu 20.04, installed it at the time using the official Ubuntu apt-repo, and now it seems we cannot upgrade because we can’t follow the documented upgrade path from MongoDB 3.6.8 → 4.0 → 4.2 → 4.4 → 5.0. Which in turn means we cannot upgrade Graylog to its latest version.

Has there been any updates or progress made on this issue? Are Ubuntu 20.04 users stuck now or is there a way to get around this?

For anyone running into this issue as well: I managed to get around this by using dockerized mongodb’s for versions 4.0 en 4.2. Both of these also come with the accompanying mongo-shell, which you can start with a docker -exec ... command.

Steps are roughly:

  • install docker-engine on your ubuntu-20.04 machine (Install Docker Engine on Ubuntu | Docker Docs)
  • shut down your current mongodb
  • copy its data directory and chown it to the user with UID 999 (default one used by the docker-engine/container)
  • create a mongo-config file to use within the docker container that
    • binds mongodb to localhost
    • tells mongo to use the (default) /data/db folder as its datafolder

You can then start the mongo-docker container and

  • map your config-file to the container
  • map your copied-and-chowned datafolder to the mongdb data folder inside the container
  • provide a parameter to mongodb as part of the container-start command that tells it to use your mapped config file

which (in my case) was this:
sudo docker run -d --name mongodb40 -p 27017:27017 -v /var/lib/mongodb.docker:/data/db -v /etc/mongodb.docker.yml:/etc/mongodb.yml mongo:4.0.28 --config /etc/mongodb.yml
You can then connect with the mongo-shell provided with the container:
sudo docker exec -it mongodb40 mongo -u <user> -p --authenticationDatabase <auth-db>
with the appropriate user and authenticationdatabase and execute the necessary command to upgrade the database (i.e. check and set the featureCompatibilityVersion).
After that, shut down the container and repeat with a container for the 4.2 version:
sudo docker run -d --name mongodb42 -p 27017:27017 -v /var/lib/mongodb.docker:/data/db -v /etc/mongodb.docker.yml:/etc/mongodb.yml mongo:4.2.24 --config /etc/mongodb.yml
Same trick for the shell, upgrade-command etc.

You now have that copied mongodb-datafolder upgraded to version 4.2, and you can then

  • shutdown the 4.2 container
  • uninstall mongo 3.6.8
  • add the apt-repo for version 4.4 and install
  • re-chown (and maybe copy) the upgraded datafolder
  • fire up mongodb 4.4 and perform the upgrade to that version (make sure it uses the upgraded datafolder)

When all is done you can uninstall the docker-engine.

Hope this helps anyone else running into the same situation.

1 Like