Skip to main content
Very ImportantMongoDB backup must be taken before performing the operation:
mongodump --host <IP_ADDRESS> --port=25080 --username=<USERNAME> --password=<PASSWORD> --authenticationDatabase=admin --gzip --archive=/<DIRECTORY>/apinizer-backup-v<CURRENT_VERSION>--<DATE>--1.archive
This example was performed on Ubuntu 22.04.

MongoDB 4.4 to 5.0 Upgrade

1) Updating Secondary Nodes from MongoDB 4.4 to 5.0

First, all MongoDB secondary nodes are updated to version 5.0 one by one.
1

Stop MongoDB service

sudo apt-mark unhold mongo*
sudo systemctl stop mongod
2

Add MongoDB 5.0 repository

# MongoDB 5.0 key is added
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

# MongoDB 5.0 Repository is added
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

sudo apt update
3

Install MongoDB 5.0

When installing the update, you must answer the config file update question with N to preserve your existing configuration file.
sudo apt install -y mongodb-org=5.0.6 mongodb-org-server=5.0.6 mongodb-org-shell=5.0.6 mongodb-org-mongos=5.0.6 mongodb-org-tools=5.0.6
Very ImportantDuring installation, the system asks whether to rewrite the config file. If the configuration file is accidentally overwritten here, it must be restored to the old setting.
# sudo vi /etc/mongod.conf
# The old file is as follows by default
storage:
  dbPath: /var/lib/mongodb
  wiredTiger:
    engineConfig:
      cacheSizeGB: 2

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

net:
  port: 25080
  bindIp: 0.0.0.0

replication:
  replSetName: apinizer-replicaset

security:
  authorization: enabled
  keyFile: /etc/mongodb/keys/mongo-key

setParameter:
  transactionLifetimeLimitSeconds: 300

processManagement:
  timeZoneInfo: /usr/share/zoneinfo
1

Start MongoDB service

sudo apt-mark hold mongo*
sudo systemctl start mongod
sudo systemctl status mongod
2

Check replica set status

Replica set status is checked by connecting to any node:
mongo mongodb://<NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

# Replica Set Status is Checked
rs.status()

2) Stepping Down a Node in Primary Role to Secondary Role

Connect to the primary node and step down the primary node’s role to secondary to allow a new primary node to be selected.
1

Connect to Primary Node

mongo mongodb://<PRIMARY_NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p
2

Step down Primary Node to Secondary Node

# Primary Node is stepped down to Secondary Node
rs.stepDown()
3

Check new Primary Node

After waiting a bit, it is checked that one of the Secondary Nodes has become Primary Node:
rs.status()

3) Updating Node That Left Primary Role from MongoDB 4.4 to 5.0

1

Stop MongoDB service

sudo apt-mark unhold mongo*
sudo systemctl stop mongod
2

Add MongoDB 5.0 repository

# Add MongoDB 5.0 key and update repository
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

sudo apt update
3

Install MongoDB 5.0

When installing the update, you must answer the config file update question with N to preserve your existing configuration file.
sudo apt install -y mongodb-org=5.0.6 mongodb-org-server=5.0.6 mongodb-org-shell=5.0.6 mongodb-org-mongos=5.0.6 mongodb-org-tools=5.0.6
4

Start MongoDB service

sudo apt-mark hold mongo*
sudo systemctl start mongod
sudo systemctl status mongod
5

Check replica set status

Replica set status is checked by connecting to any node:
mongosh mongodb://<NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

# Replica Set status is checked
rs.status()

4) MongoDB 5.0 Feature Compatibility Check

After all Nodes have transitioned to MongoDB 5.0, before transitioning to MongoDB 6.0, the feature compatibility setting is set to 5.0 (on Primary Node).
1

Connect to Primary Node

mongosh mongodb://<PRIMARY_NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

use admin
2

Check feature compatibility

If the feature compatibility appears as 4 in the output of the following command, it should be updated to 5:
db.runCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
3

Update feature compatibility

If the value is not 5.0, you can change it with the following command:
db.adminCommand({ setFeatureCompatibilityVersion: "5.0" })

MongoDB 5.0 to 6.0 Upgrade

5) Updating Secondary Nodes from MongoDB 5.0 to 6.0

After ensuring all MongoDB replicas have transitioned to version 5.0, you can transition to version 6.0. First, start by updating all secondary nodes sequentially.
1

Stop MongoDB service

sudo apt-mark unhold mongo*
sudo systemctl stop mongod
2

Add MongoDB 6.0 repository

# MongoDB 6.0 key is added and repository is updated
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

sudo apt update
3

Install MongoDB 6.0

# Update is installed
sudo apt install -y mongodb-org=6.0.0 mongodb-org-server=6.0.0 mongodb-org-shell=6.0.0 mongodb-org-mongos=6.0.0 mongodb-org-tools=6.0.0
4

Start MongoDB service

sudo apt-mark hold mongo*
sudo systemctl start mongod
sudo systemctl status mongod
5

Check replica set status

Check replica set status by connecting to any node:
mongosh mongodb://<NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

# Replica Set status is checked
rs.status()

6) Stepping Down a Node in Primary Role to Secondary Role

1

Connect to Primary Node

mongosh mongodb://<PRIMARY_NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p
2

Step down Primary Node to Secondary Node

# Primary Node is stepped down to Secondary Node
rs.stepDown()
3

Check new Primary Node

After waiting a bit, it is checked that one of the upgraded Secondary Nodes has become Primary:
rs.status()

7) Updating Node That Left Primary Role from MongoDB 5.0 to 6.0

1

Stop MongoDB service

sudo apt-mark unhold mongo*
sudo systemctl stop mongod
2

Add MongoDB 6.0 repository

# MongoDB 6.0 key is added and repository is updated
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

sudo apt update
3

Install MongoDB 6.0

# Update is installed
sudo apt install -y mongodb-org=6.0.0 mongodb-org-server=6.0.0 mongodb-org-shell=6.0.0 mongodb-org-mongos=6.0.0 mongodb-org-tools=6.0.0
4

Start MongoDB service

sudo apt-mark hold mongo*
sudo systemctl start mongod
sudo systemctl status mongod
5

Check replica set status

Check replica set status by connecting to any node:
mongosh mongodb://<NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

# Replica Set status is checked
rs.status()

8) MongoDB 6.0 Feature Compatibility Check

After all Nodes have transitioned to MongoDB 6.0, the feature compatibility setting is set to 6.0 (on Primary Node).
1

Connect to Primary Node

mongosh mongodb://<PRIMARY_NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

use admin
2

Check feature compatibility

If the feature compatibility appears as 5 in the output of the following command, it should be updated to 6:
db.runCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
3

Update feature compatibility

If the value is not 6.0, you can change it with the following command:
db.adminCommand( { setFeatureCompatibilityVersion: "6.0" } )

MongoDB 6.0 to 7.0 Upgrade

9) Updating Secondary Nodes from MongoDB 6.0 to 7.0

After ensuring all MongoDB replicas have transitioned to version 6.0, you can transition to version 7.0. First, start by updating all secondary nodes sequentially.
1

Stop MongoDB service

sudo apt-mark unhold mongo*
sudo systemctl stop mongod
2

Add MongoDB 7.0 repository

# MongoDB 7.0 key is added and repository is updated
wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

sudo apt update
3

Install MongoDB 7.0

# Update is installed
sudo apt install -y mongodb-org=7.0.0 mongodb-org-server=7.0.0 mongodb-org-shell=7.0.0 mongodb-org-mongos=7.0.0 mongodb-org-tools=7.0.0
4

Start MongoDB service

sudo apt-mark hold mongo*
sudo systemctl start mongod
sudo systemctl status mongod
5

Check replica set status

Check replica set status by connecting to any node:
mongosh mongodb://<NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

# Replica Set status is checked
rs.status()

10) Stepping Down a Node in Primary Role to Secondary Role

1

Connect to Primary Node

mongosh mongodb://<PRIMARY_NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p
2

Step down Primary Node to Secondary Node

# Primary Node is stepped down to Secondary Node
rs.stepDown()
3

Check new Primary Node

After waiting a bit, it is checked that one of the upgraded Secondary Nodes has become Primary:
rs.status()

11) Updating Node That Left Primary Role from MongoDB 6.0 to 7.0

1

Stop MongoDB service

sudo apt-mark unhold mongo*
sudo systemctl stop mongod
2

Add MongoDB 7.0 repository

# MongoDB 7.0 key is added and repository is updated
wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

sudo apt update
3

Install MongoDB 7.0

# Update is installed
sudo apt install -y mongodb-org=7.0.0 mongodb-org-server=7.0.0 mongodb-org-shell=7.0.0 mongodb-org-mongos=7.0.0 mongodb-org-tools=7.0.0
4

Start MongoDB service

sudo apt-mark hold mongo*
sudo systemctl start mongod
sudo systemctl status mongod
5

Check replica set status

Check replica set status by connecting to any node:
mongosh mongodb://<NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

# Replica Set status is checked
rs.status()

12) MongoDB 7.0 Feature Compatibility Check

After all Nodes have transitioned to MongoDB 7.0, the feature compatibility setting is set to 7.0 (on Primary Node).
1

Connect to Primary Node

mongosh mongodb://<PRIMARY_NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

use admin
2

Check feature compatibility

If the feature compatibility appears as 6 in the output of the following command, it should be updated to 7:
db.runCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
3

Update feature compatibility

If the value is not 7.0, you can change it with the following command:
db.adminCommand( { setFeatureCompatibilityVersion: "7.0", confirm: true } )

MongoDB 7.0 to 8.0 Upgrade

13) Updating Secondary Nodes from MongoDB 7.0 to 8.0

After ensuring all MongoDB replicas have transitioned to version 7.0, you can transition to version 8.0. First, start by updating all secondary nodes sequentially.
1

Stop MongoDB service

sudo apt-mark unhold mongo*
sudo systemctl stop mongod
2

Add MongoDB 8.0 repository

# MongoDB 8.0 key is added and repository is updated
wget -qO - https://www.mongodb.org/static/pgp/server-8.0.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

sudo apt update
3

Install MongoDB 8.0

# Update is installed
sudo apt install -y mongodb-org=8.0.0 mongodb-org-server=8.0.0 mongodb-org-shell=8.0.0 mongodb-org-mongos=8.0.0 mongodb-org-tools=8.0.0
4

Start MongoDB service

sudo apt-mark hold mongo*
sudo systemctl start mongod
sudo systemctl status mongod
5

Check replica set status

Check replica set status by connecting to any node:
mongosh mongodb://<NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

# Replica Set status is checked
rs.status()

14) Stepping Down a Node in Primary Role to Secondary Role

1

Connect to Primary Node

mongosh mongodb://<PRIMARY_NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p
2

Step down Primary Node to Secondary Node

# Primary Node is stepped down to Secondary Node
rs.stepDown()
3

Check new Primary Node

After waiting a bit, it is checked that one of the upgraded Secondary Nodes has become Primary:
rs.status()

15) Updating Node That Left Primary Role from MongoDB 7.0 to 8.0

1

Stop MongoDB service

sudo apt-mark unhold mongo*
sudo systemctl stop mongod
2

Add MongoDB 8.0 repository

# MongoDB 8.0 key is added and repository is updated
wget -qO - https://www.mongodb.org/static/pgp/server-8.0.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

sudo apt update
3

Install MongoDB 8.0

# Update is installed
sudo apt install -y mongodb-org=8.0.0 mongodb-org-server=8.0.0 mongodb-org-shell=8.0.0 mongodb-org-mongos=8.0.0 mongodb-org-tools=8.0.0
4

Start MongoDB service

sudo apt-mark hold mongo*
sudo systemctl start mongod
sudo systemctl status mongod
5

Check replica set status

Check replica set status by connecting to any node:
mongosh mongodb://<NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

# Replica Set status is checked
rs.status()

16) MongoDB 8.0 Feature Compatibility Check

After all Nodes have transitioned to MongoDB 8.0, the feature compatibility setting is set to 8.0 (on Primary Node).
1

Connect to Primary Node

mongosh mongodb://<PRIMARY_NODE_IP>:25080 --authenticationDatabase "admin" -u "apinizer" -p

use admin
2

Check feature compatibility

If the feature compatibility appears as 7 in the output of the following command, it should be updated to 8:
db.runCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
3

Update feature compatibility

If the value is not 8.0, you can change it with the following command:
db.adminCommand( { setFeatureCompatibilityVersion: "8.0", confirm: true } )