Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

MongoDB upgrade requires that you must upgrade to each version of MongoDB along the way.

This document will follow the MongoDB upgrade path from 4.2 → 4.4 → 5.0 → 6.0, with the document structured as follows:

  1. Prerequisites
  2. Upgrade Preparation
  3. Upgrade from MongoDB 4.2 to MongoDB 4.4
  4. Upgrade from MongoDB 4.4 to MongoDB 5.0
  5. Upgrade from MongoDB 5.0 to MongoDB 6.0
  6. Services Restart
  7. Clean-up

Notes

NOTE: All Linux commands in this document are run at root level: you need access to root via su or sudo -i

Set these two environment variables with your MongoDB admin username and password so that these script examples can be used:

export YOUR_USERNAME=opUserRW
export YOUR_PASSWORD=t0pS3cr3tpw

...

setMongoFcv() {
    if which mongosh; then  local MONGOSH=mongosh;   else   local MONGOSH=mongo; fi;
    $MONGOSH -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"$1\" } )"
}

Code Block
languagebash
showMongoFcv() {
        if which mongosh; then  local MONGOSH=mongosh;   else   local MONGOSH=mongo; fi;
        $MONGOSH -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval "db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )"
}

setMongoFcv() {
        if which mongosh; then  local MONGOSH=mongosh;   else   local MONGOSH=mongo; fi;
        $MONGOSH -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"$1\" } )"
}

Another useful alias to show fcv is

alias showfcv='mongo -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval "db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )"'

showfcv() {
        if which mongosh; then  local MONGOSH=mongosh;   else   local MONGOSH=mongo; fi;
        $MONGOSH -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval "db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )"
}

showfcv() {
        if which mongosh; then  local MONGOSH=mongosh;   else   local MONGOSH=mongo; fi;
        mongo -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval "db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )"
}

showfcv ()
{
    if which mongosh; then
        local MONGOSH=mongosh;
    else
        local MONGOSH=mongo;
    fi;
    $MONGOSH -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval "db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )"
}

showMongoFcv () {
    if which mongosh; then  local MONGOSH=mongosh;   else   local MONGOSH=mongo; fi;
    $MONGOSH -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval "db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )"
}
setMongoFcv () 
{
    if which mongosh; then  local MONGOSH=mongosh;   else   local MONGOSH=mongo; fi;
    $MONGOSH -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"$1\" } )"
}

    if which mongosh; then  local MONGOSH=mongosh;   else   local MONGOSH=mongo; fi;
    
}

...

Table of Contents

Table of Contents

...

MongoDB upgrade requires that you must upgrade to each version of MongoDB along the way.

This document will follow the MongoDB upgrade path from 4.2 → 4.4 → 5.0 → 6.0, with the document structured as follows:

  1. Prerequisites
  2. Upgrade Preparation
  3. Upgrade from MongoDB 4.2 to MongoDB 4.4
  4. Upgrade from MongoDB 4.4 to MongoDB 5.0
  5. Upgrade from MongoDB 5.0 to MongoDB 6.0
  6. Services Restart
  7. Clean-up

Notes

NOTE: All Linux commands in this document are run at root level: you need access to root via su or sudo -i

Set these two environment variables with your MongoDB admin username and password so that these script examples can be used:


Code Block
languagebash
export YOUR_USERNAME=opUserRW
export YOUR_PASSWORD=t0pS3cr3tpw

showMongoFcv() {
    if which mongosh; then  local MONGOSH=mongosh;   else   local MONGOSH=mongo; fi;
    $MONGOSH -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval "db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )"
}

setMongoFcv() {
    if which mongosh; then  local MONGOSH=mongosh;   else   local MONGOSH=mongo; fi;
    $MONGOSH -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"$1\" } )"
}


Table of Contents

Table of Contents


Prerequisites for Upgrading MongoDB 4.2 to MongoDB 6.0

This document outlines the process to bring MongoDB up to version 6.0. There are a series of prerequisites that determine the type of update required. This document outlines the process for MongoDB Standalone.

...

This command will execute all outstanding upgrades. Check for any errors and address as required.

Once this step is completed you may optionally reboot the system. This can clear out any memory leaks and instabilities in the system that occur due to long uptimes.

Shutdown All FirstWave Daemons

Prior to commencing into the MongoDB upgrade cycles it is required to shutdown all FirstWave processes.

The following commands are used to complete this task

/usr/local/omk/bin/checkomkdaemons.sh stop
systemctl stop nmis9d

# confirm that the daemons have stopped
/usr/local/omk/bin/checkomkdaemons.sh status
systemctl status nmis9d

Example Command and Output

user@servername:~/installers# systemctl status nmis9d
● nmis9d.service - FirstWave NMIS9 Daemon
     Loaded: loaded (/etc/systemd/system/nmis9d.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Thu 2024-06-27 17:32:05 AEST; 26s ago
    Process: 252049 ExecStartPre=/bin/sh -c sleep 3 (code=exited, status=0/SUCCESS)
    Process: 252058 ExecStart=/usr/local/nmis9/bin/nmisd (code=exited, status=0/SUCCESS)
   Main PID: 252105 (code=exited, status=0/SUCCESS)
        CPU: 1h 23.745s

Jun 27 17:32:04 m6poller1 systemd[1]: Stopping FirstWave NMIS9 Daemon...
Jun 27 17:32:05 m6poller1 systemd[1]: nmis9d.service: Succeeded.
Jun 27 17:32:05 m6poller1 systemd[1]: Stopped FirstWave NMIS9 Daemon.
Jun 27 17:32:05 m6poller1 systemd[1]: nmis9d.service: Consumed 1h 23.745s CPU time.

Upgrade from MongoDB 4.2 to MongoDB 4.4

Prepare the Database for Upgrade

Check the database compatibility mode is set to "4.2"as required.

Once this step is completed you may optionally reboot the system. This can clear out any memory leaks and instabilities in the system that occur due to long uptimes.

Shutdown All FirstWave Daemons

Prior to commencing into the MongoDB upgrade cycles it is required to shutdown all FirstWave processes.

The following commands are used to complete this task

/usr/local/omk/bin/checkomkdaemons.sh stop
systemctl stop nmis9d

# confirm that the daemons have stopped
/usr/local/omk/bin/checkomkdaemons.sh status
systemctl status nmis9d


Example Command and Output

user@servername:~/installers# systemctl status nmis9d
● nmis9d.service - FirstWave NMIS9 Daemon
     Loaded: loaded (/etc/systemd/system/nmis9d.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Thu 2024-06-27 17:32:05 AEST; 26s ago
    Process: 252049 ExecStartPre=/bin/sh -c sleep 3 (code=exited, status=0/SUCCESS)
    Process: 252058 ExecStart=/usr/local/nmis9/bin/nmisd (code=exited, status=0/SUCCESS)
   Main PID: 252105 (code=exited, status=0/SUCCESS)
        CPU: 1h 23.745s


Jun 27 17:32:04 m6poller1 systemd[1]: Stopping FirstWave NMIS9 Daemon...
Jun 27 17:32:05 m6poller1 systemd[1]: nmis9d.service: Succeeded.
Jun 27 17:32:05 m6poller1 systemd[1]: Stopped FirstWave NMIS9 Daemon.
Jun 27 17:32:05 m6poller1 systemd[1]: nmis9d.service: Consumed 1h 23.745s CPU time.


Upgrade from MongoDB 4.2 to MongoDB 4.4


Prepare the Database for Upgrade

Check the database compatibility mode is set to "4.2"

mongo -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval 'db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )'

The result should be as follows ensuring that the value 4.2 is set

{ "featureCompatibilityVersion" : "4.2", "ok" : 1 }

If MongoDB is on version 4.2 and the featureCompatibilityVersion is not "4.2" then set this with the following command

mongo -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval 'db.adminCommand( { setFeatureCompatibilityVersion: "4.2" } )';

As before, the check the featureCompatibilityVersion again confirming the correct value

Example Command and Output

mongo -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval 'db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )'

...

 
{ "featureCompatibilityVersion" : "4.2", "ok" : 1 }

...

Debian - Install MongoDB 4.

...

mongo -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval 'db.adminCommand( { setFeatureCompatibilityVersion: "4.2" } )';

As before, the check the featureCompatibilityVersion again confirming the correct value

Example Command and Output

mongo -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval 'db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )'
 
{ "featureCompatibilityVersion" : "4.2", "ok" : 1 }

Debian - Install MongoDB 4.4 Repo and Upgrade

Details available here:

...

4 Repo and Upgrade

Details available here:

https://www.mongodb.com/docs/v4.4/release-notes/4.4-upgrade-standalone/ and https://www.mongodb.com/docs/v4.4/tutorial/install-mongodb-on-debian/


Commands summarised here:

systemctl stop mongod

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

echo "deb [ trusted=yes ] http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list


curl -fsSL https://www.mongodb.

...

org/static/

...

pgp/

...

Commands summarised here:

systemctl stop mongod

wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-4.4.
asc | sudo apt-key addgpg \
   --dearmor
echo "deb [
trusted=yes ] httparch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-4.4.gpg ] https://repo.mongodb.org/apt/debian busterubuntu focal/mongodb-org/4.4 mainmultiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list



sudo apt-get update

sudo apt-get upgrade mongodb-org -y  --allow-unauthenticated

mongod --version

systemctl stop mongod
systemctl start mongod
systemctl daemon-reload
systemctl is-active mongod

...

systemctl stop mongod

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-5.0.gpg --dearmor

echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-5.0.gpg] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

sudo apt-get update

sudo apt-get upgrade -y mongodb-org

------------------------------------

If you get an error

Errors were encountered while processing:
 /var/cache/apt/archives/mongodb-org-database-tools-extra_5.0.27_amd64.deb

Fix it by using:

sudo dpkg -i --force-overwrite /var/cache/apt/archives/mongodb-org-database-tools-extra_5.0.27_amd64.deb

then

sudo apt-get upgrade -y mongodb-org

and answer N to keep your currently installed version of /etc/mongod.conf

-------------------------------------

systemctl stop mongod ; systemctl start mongod ; systemctl daemon-reload ; systemctl is-active mongod ; systemctl status mongod


...

systemctl stop mongod

wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg --dearmor

echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

sudo apt-get update

sudo apt-get upgrade -y mongodb-org
    and answer N to keep your currently installed version of /etc/mongod.conf


systemctl stop mongod ; systemctl start mongod ; systemctl daemon-reload ; systemctl is-active mongod ; systemctl status mongod

...

You can now browse to your FirstWave instance of NMISwith:

https://<yourserver>/omk

You will get a screen similar to the following which will give you a status on all installed servicesmodules:

TODO - Update Screenshot 

...

Image Added