Mongodb 4.0 to mongodb 4.2

Description

Server Setup Information

  • Version of Rocket.Chat Server: 4.3.2
  • Operating System: CentOS Linux 7 (Core)
  • Deployment Method:
  • Number of Running Instances:
  • DB Replicaset Oplog: 4.0.23 / mmapv1 (oplog Enabled)
  • NodeJS Version: v12.22.1
  • MongoDB Version: 4.0.23 / mmapv1 (oplog Enabled)
  • Proxy:
  • Firewalls involved: iptables

Any additional Information

Hi Team,

Good Day.

Do we have steps how to upgrade mongodb 4.0 to 4.2 in centos?

Thanks

Someone…please i need it too.

I’m using this script to go from 4.0.25 to 4.4.9 Maybe it will help you:

#!/usr/bin/env bash
sudo docker rm -f rocketchat-mongo-upgrade
set -e
sudo docker pull mongo:4.2.17
sudo docker pull mongo:4.4.9
sudo docker pull mongo:5.0.3
sudo docker-compose -p gql stop
sudo docker start rocketchat-mongo
until sudo docker exec rocketchat-mongo mongo
do
    echo "Waiting for Mongo to start..."
    sleep 1
done
sudo docker exec -u0 rocketchat-mongo rm -r -f /dump
sudo docker exec -u0 rocketchat-mongo mkdir /dump
echo "Starting dump.."
sudo docker exec -u0 rocketchat-mongo mongodump --out=/dump
sudo docker exec -u0 rocketchat-mongo tar -czf /dump.tgz /dump
sudo docker cp rocketchat-mongo:/dump.tgz dump.tgz
echo "Backup complete. Stopping old Mongo"
sudo docker stop rocketchat-mongo
sudo rm -r -f data
echo "Starting new Mongo.."
sudo docker run -d \
  --name rocketchat-mongo-upgrade \
  -v $(pwd)/data:/data/db \
 mongo:4.0.25 \
 mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger
sudo docker cp dump.tgz rocketchat-mongo-upgrade:/dump.tgz
sudo docker exec rocketchat-mongo-upgrade tar -xzf /dump.tgz
until sudo docker exec rocketchat-mongo-upgrade mongo
do
    echo "Waiting for Mongo to start..."
    sleep 1
done
echo "Initializing Mongo..."
sudo docker exec rocketchat-mongo-upgrade mongo 127.0.0.1/rocketchat --eval "rs.initiate({_id: 'rs0', members: [ { _id: 0, host: 'localhost:27017' } ]})"
echo "Restoring database.."
sudo docker exec -u0 rocketchat-mongo-upgrade mongorestore /dump
echo "Cleaning up.."
sudo docker stop rocketchat-mongo-upgrade
sudo docker rm -v rocketchat-mongo-upgrade
sudo rm dump.tgz
echo
echo "Upgrading mongo verstion to 4.2.17.."
sudo docker run -d \
  --name rocketchat-mongo-upgrade \
  -v $(pwd)/data:/data/db \
 mongo:4.2.17 \
 mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger
until sudo docker exec rocketchat-mongo-upgrade mongo
do
    echo "Waiting for Mongo to start..."
    sleep 1
done
sudo docker exec rocketchat-mongo-upgrade mongo 127.0.0.1/rocketchat --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"4.2\" } )"
sudo docker logs rocketchat-mongo-upgrade
sudo docker stop rocketchat-mongo-upgrade
sudo docker rm -v rocketchat-mongo-upgrade
echo
echo "Upgrading mongo verstion to 4.4.9.."
sudo docker run -d \
  --name rocketchat-mongo-upgrade \
  -v $(pwd)/data:/data/db \
 mongo:4.4.9 \
 mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger
until sudo docker exec rocketchat-mongo-upgrade mongo
do
   echo "Waiting for Mongo to start..."
   sleep 1
done
sudo docker exec rocketchat-mongo-upgrade mongo 127.0.0.1/rocketchat --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"4.4\" } )"
sudo docker logs rocketchat-mongo-upgrade
sudo docker stop rocketchat-mongo-upgrade
sudo docker rm -v rocketchat-mongo-upgrade
echo
echo "Cleaning up container images."
sudo docker image prune -a
1 Like

Hi @stefan.badenhorst . I really appreciate your post but it seems for docker or vm? Can you please provide steps for a standalone CentOS 7 machine?

Thanks again!

hi, the commands are for docker.

Migrating anything, mongo or rocket.chat itself for a standalone deployment is more trickier to do with scripts as the environment may not be consistent (paths, dependencies and what not)

Also, unless you have a very strong requirement to do otherwise, you should run Rocket.Chat with docker (for small to mid sized deployments) or k8s for bigger deployments.

With that said, migrating mongo from 4.0 to 4.2 should be a matter of dumping and restoring. For that, we usually recommend to follow mongo docs itself.

THanks!

If you want to use WiredTiger then you need to do this before you start the upgrade:

The main thing is that you need to make a backup using mongo dump mongodump --out=/dump
Then you need to start a fresh instance with the WiredTiger storage engine and do a restore mongorestore /dump

To upgrade version you need to install the new version of mongo over the existing one (so you use the same database files) and start it up. You can only go up 1 version at a time. (not a problem in your case)
Once it is started it will upgrade your db files. Then if you are happy with the upgrade you need to run: mongo 127.0.0.1/rocketchat --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"4.2\" } )"

Please read the documentation on the mongodb website. I’ve only ever upgraded a single node.
And make a backup of your data before you start.

1 Like