How to upgrade mongoDB from 4.0 to 5.0?

Description

Rocket .Chat server running in Google Cloud vm machine. I want to upgrade the mongoDB version from 4.0 to 5.0. What is the best practice to do the upgrade? including taking backup, restore, etc…

Server Setup Information

  • Version of Rocket.Chat Server:
  • Operating System: Ubuntu 18.04
  • Deployment Method: /tar/etc (using manual installation guide)
  • Number of Running Instances: 1
  • DB Replicaset Oplog:
  • NodeJS Version: v14.19.0
  • MongoDB Version: 4.0.10 / mmapv1
  • Proxy:
  • Firewalls involved:

Any additional Information

All the available guides are either for docker or snap. There is no clear step by step guide for manual installation.
I would appreciate if someone can provide a step by step guide to do the upgrading.

Thank you

Hi!

You will also need to migrate from MMAPV1 to WiredTiger.

Consider that mongo 5.0 has some CPU incompatibilities.

It will be basically a dump and restore process. This is more a mongo process than it is a Rocket.Chat process.

Also, consider using docker/k8s instead of manual deployment.

Thank you for your response.
“You will also need to migrate from MMAPV1 to WiredTiger.” I am aware of this step I will have to do that first.
If mongo 5.0 has some incompatibilities issues I will upgrade to 4.4 for now and maybe later to 5.
Currently I am also thinking move to a cheaper server to host RocketChat, currently it is installed in a vm machine running in Google Cloud.
You have mentioned Docker/k8s however my previous installation was manual, how can I migrate to Docker is it easy thing to do?
Also If I moved to a new hosting server, I just need the backup of the mongo database from the current server right?

Hi! Docker is way easier.

All versions, like node, dependencies and what not is handled by the docker container.

Migrating should be a matter of dumping and restoring the mongo database.

If your filesystem for uploads is GRIDfs, the files should be already there. Otherwise, you need to copy them.

You will then spin up a rocket.chat docker container with the same version you are already at, restore the database, and start migrating and testing.

Mongo 4.4 end support in February 2024.

Great thank you for the information.
I will use Docket installation on the new server.
However I have a few more questions if you dont mind, my current version NodeJs 14.19.0 and MongoDB 4.0.10, RocketChat 4.8.1.
I am going to install the latest versions on the new server using Docket as you have suggested (it would be great if you could provide me with step by step guide on how to install Rocketchat with Docker)
Will there be any issue if I restore the database with mentioned versions into the new version?
Also when i did the dump on the server I did not use docker. This is how I did it mongodumb --out /backup.
Last but not least why Docker no Snap ?

Thank you for your help

Hi!

You should not have any problems regarding versions and dependencies while using docker. It will isolate your environment and deliver all the necessary bits.

there is a nice step by step here:

With Docker (or Kubernetes) you have more control over the environment, and will not depend on host versions. Also, it’s easier to scale.

Snap is easy to install, but will be closely tied to the host you are running, while docker you can move your deployment without a lot of hassle.

Hi @dudanogueira thank you for the information.
The steps to install Rocket.Chat using Docker is clear and simple. I will install it in the new server.
One last thing I don`t how to approach it, since I have my monog backup in the old server.
What should I do in order to use the backup from the old server in the new server where I installed RocketChat using docker?
I hope I delivered my point clearly

Thank you
Ghaleb

Hi!

Once you have the dump at hands, and have a new, clean, fresh install of Rocket.Chat using docker, with the same version from the dump (you can upgrade later) you need to restore the data into the docker mongo container.

Here you can have the steps for that:

After discovering the name of the mongo docker container:

docker exec -i <database_name> sh -c 'mongorestore --archive' < db.dump

Here is a very simple step by step guide i found for upgrading MongoDB from v4.0 to v5.0. Hope this helps!

1 Like

Hi I have done the fresh install of Rokcet.Chat with same version of the old server.
However the database restore step still not clear to me. As you know I was not using docker there and the dump is created using mongodump --out mongobackup inside are those files


So how can I restore this in docker?

Thank you for sharing, this will be helpful after I finish restoring the data.