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.

Hello,
recently new Rocket.Chat 5 appeared so I need to upgrade my mongodb and I have problems with that, I found some examples on the Internet but none of them work for me, can someone help me with mongo upgrade?

I tried upgrade mongo installation - upgrading mongodb from 3.6 to 4.0 - Server Fault

sudo systemctl stop mongod

wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add -

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

results are OK

sudo apt-get update && sudo apt-get install -y mongodb-org=4.0.14 mongodb-org-server=4.0.14 mongodb-org-shell=4.0.14 mongodb-org-mongos=4.0.14 mongodb-org-tools=4.0.14

I got these

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
sudo lsof /var/lib/dpkg/lock-frontend

unattende 122112 root    5uW  REG    8,1        0 3016028 /var/lib/dpkg/lock-frontend

sudo kill -9 122112

sudo rm /var/lib/dpkg/lock-frontend

sudo dpkg --configure -a

I did again

sudo apt-get update && sudo apt-get install -y mongodb-org=4.0.14 mongodb-org-server=4.0.14 mongodb-org-shell=4.0.14 mongodb-org-mongos=4.0.14 mongodb-org-tools=4.0.14

got this

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

Hi!

Manual deployments can lead to multiple dependencies and installation errors. that makes it hard to troubleshoot.

We strongly suggest migrating to a docker/k8s environment, as you can avoid this kind os issues.

A good rule of thumb is to set up a docker deployment with the same version you have now, dump data from manual deployment, restore it in docker, test, and start migrating without jumping majors.

Let me know if this helps :slight_smile:

Hello,
probably you are right that it will be a good solution, do you know a good step-by-step how-to?

We have a very straight forward to install Rocket.Chat using docker here:

as well as backup and restore instructions here:

With that you can spin up the environment, dump your actual data, and restore into this new docker deployment and start migrating :slight_smile:

I will try this new possibility, thx