Rocket.Chat's Community Open Call 🎤 Jan 19th, 2022 Join us!

Upgrade mongo 3.6 to 4.x

Hello,
recently I have upgrade my rocket.chat to version 4.2 and there was an information about upgrade mongo from 3.6 to 4.2.
I found this page Upgrade MongoDB from 3.4 to 4.0 and enable transactions features | docs-community-dev (opensilex.github.io) how to upgrade.
I did these steps:

  1. Dump your database
mongodump --host localhost

2.3. mongdb

sudo systemctl status mongodb
sudo systemctl stop mongodb
sudo systemctl status mongodb
  1. GPG Key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
  1. Add MongoDB 4.0 repository to apt list files
    Install MongoDB Community Edition on Ubuntu — MongoDB Manual
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
ls -lrt /etc/apt/sources.list.d/
  1. Remove older version and database files
sudo apt-get purge mongodb-org*

Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package mongodb-org*
E: Couldn’t find any package by glob ‘mongodb-org*’
E: Couldn’t find any package by regex ‘mongodb-org*’

sudo rm -rf /var/lib/mongodb
sudo mkdir /var/lib/mongodb/
sudo chown -R mongodb:mongodb /var/lib/mongodb/
  1. Update apt and install new version
sudo apt-get update
sudo apt-get install mongodb-org


Unpacking mongodb-org (4.0.27) …
Errors were encountered while processing:
/var/cache/apt/archives/mongodb-org-server_4.0.27_amd64.deb
/var/cache/apt/archives/mongodb-org-mongos_4.0.27_amd64.deb
/var/cache/apt/archives/mongodb-org-tools_4.0.27_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

  1. Restart MongoDB service
sudo systemctl enable mongodb

Synchronizing state of mongodb.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mongodb
Failed to enable unit: Unit file /etc/systemd/system/mongodb.service is masked.

After that error I ran this command:

sudo systemctl unmask mongodb

Removed /etc/systemd/system/mongodb.service
then

sudo systemctl enable mongodb

mongodb.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mongodb

sudo systemctl start mongodb

Job for mongodb.service failed because the control process exited with error code.
See “systemctl status mongodb.service” and “journalctl -xe” for details.

How should I properly upgrade mongodb?

Hi!

This looks like a package installation problem to me.

I personally prefer containers deploys, as you don’t have to deal with this kind of problems, and looking for solutions is easier as you have a more relatable environments to others.

Bear in mind that Rocket.Chat 4.x still supports Mongo 3.6, and will only drop support for the next major release, according to here:

Hi,
probably you are right that container version is better than normal installation but I installed Rocket.Chat some time ago and it still works.

I’ve seen this document that Rocket.Chat 4.x still supports Mongo 3.6, but I thought I can try to upgrade Mongo (of course in may lab not production) but there was some errors.

Maybe the next version of Rocket.Chat will enable a possibility to upgrade mongo during upgrade itself, who knows.

Is your installation method from .tar.gz?

If that’s the case, there is not way to deliver automatic mongo upgrades :frowning:

This can be done with snaps, if I am not wrong, but for that method you’ll have the trade offs of snap itself.

We are about to release some content regarding deployment methods from our own @debdut.chakraborty, Rocket.Chat’s deployment specialist.

Hi,
I was deploying my Rocket.Chat from here How to Deploy Rocket.Chat on Ubuntu 18.04 | Linuxize including MongoDB.

I am also blocked in upgrading Mongo. I am using the Digital Ocean marketplace Rocket.Chat image[1]. This is Ubuntu 20.04, Rocket.Chat version 4.1.2, and MonboDB version 4.0.3.

[1] https://marketplace.digitalocean.com/apps/rocket-chat

Hi! I’ll ask our deployment specialist to give us some help here. cc @debdut.chakraborty

Hi,
it would be nice to get some help, maybe there is a way to upgrade Mongo.