Upgrade MongoDB 3.4 to 4.2

In this article we will upgrade Mongodb 3.4 to 4.2.

MongoDB Upgradation approach will be as follows;

  1. Upgrade Mongodb 3.4 to 3.6
  2. Upgrade Mongodb 3.6 to 4.0
  3. Upgrade Mongodb 4.0 to 4.2

Environments

We have 3 servers in Replica Set
a) 192.168.2.1 (Primary)
b) 192.168.2.2 (Secondary)
c) 192.168.2.3 (Hidden Node)

Upgrade Mongodb 3.4 to 3.6

Step1:

We will start with hidden node i.e 192.168.2.3
a) Shut down the mongod instance on hidden node and replace the 3.4 binary with the 3.6 binary.
b) Restart the node.
Then we will start on Secondary node i.e. 192.168.2.2
a) Shut down the mongod instance on Server and replace the 3.4 binary with the 3.6 binary.
b) Restart the node.

Step2:

Then we will start on Primary node i.e. 192.168.2.1 and Perfom below steps:
a) Initiate rs.stepDown() on Primary (192.168.2.1), through this command 192.168.2.2 will become Primary and 192.168.2.1 will become Secondary.
b) Shut down the mongod instance on Server and replace the 3.4 binary with the 3.6 binary.
c) Restart the node.

Step3:

Then we will Enable backward Compatibility via executing below Command on Primary

Now all nodes will upgrade to 3.6 version in a Replica Set.

Upgrade Mongodb 3.6 to 4.0

So before upgrading to MongoDB 4.0 from version 3.6, we have to upgrade the replica Set protocol version from pv0 to pv1 and to do the same we have to execute below set of commands on Primary as pv0 is deprecated from MongoDB 4.0 onward.

Then we will move forward for upgrading MongoDB ReplicaSet nodes from 3.6 to 4.0 and below will be the steps for same:-

Step1:

We will start on upgrade 192.168.2.3
a) Shut down the mongod instance on hidden Node and replace the 3.6 binary with the 4.0 binary.
b) Restart the node.

Step2:

Then we will start on 192.168.2.1 which will be the Secondary node and We will perform below steps:-
a) Shut down the mongod instance on Server and replace the 3.6 binary with the 4.0 binary.
b) Restart the node.

Step3:

Then we will start on Primary node 192.168.2.2 and Perfom below steps:-
a) Initiate rs.stepDown() on Primary 192.168.2.2, via this command 192.168.2.1 will become Primary and 192.168.2.2 will become Secondary.
b) Shut down the mongod instance on Server and replace the 3.6 binary with the 4.0 binary.
c) Restart the node.

Step4:

Then we will Enable backward Compatibility via executing below Commands on Primary :

Upgrade Mongodb 4.0 to 4.2

Then we will move forward for upgrading MongoDB ReplicaSet nodes from MongoDB version 4.0 to 4.2 and below will be the steps for same:-

Step1:

We will start upgrade on 192.168.2.3
a) Shut down the mongod instance on hidden node and replace the 4.0 binary with the 4.2 binary.
b) Restart the node

Step2:

Then we will start upgradation Secondary node 192.168.2.2 and We will perform below steps:-
a) Shut down the mongod instance on Server and replace the 4.0 binary with the 4.2 binary.
b) Restart the node.

Step3:

Then we will start upgradation Primary node 192.168.2.1 and Perfom below steps:
a) Initiate rs.stepDown() on Primary 192.168.2.1, via this command 192.168.2.2 will become Primary and 192.168.2.1 will become Secondary.
b) Shut down the mongod instance on Server and replace the 4.0 binary with the 4.2 binary.
c) Restart the node.

Step4:

Then we will Enable backward Compatibility via executing below Commands on Primary :

Now its completed. I told every steps in this article. You can follows these steps to upgrade mongodb 3.4 to 4.2.

All the nodes are upgraded from MongoDB 3.4 to MongoDB 4.2.

You may want to read below article to install mongodb sharded Cluster;

How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS

Dinesh Chandra Choubey
Author: Dinesh Chandra Choubey

I am a Database administrator with an 5+ years. I have hands on experience on MySQL, Mongodb , Cassandra DB's. I have experience about to configure MySQL replication, Database performance Tunning, Mongodb replicaSet configuration, MongoDB Sharding configuration and troubleshooting, Managing, extensive knowledge about MySQL and mongodb backup configuration, Implementation of ProxySQL over MySQL for High Availability.

Leave a Reply

Your email address will not be published. Required fields are marked *