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:
- Prerequisites
- Upgrade Preparation
- Upgrade from MongoDB 4.2 to MongoDB 4.4
- Upgrade from MongoDB 4.4 to MongoDB 5.0
- Upgrade from MongoDB 5.0 to MongoDB 6.0
- Services Restart
- 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 | ||
---|---|---|
| ||
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;
}
ifwhichmongosh; then
readonly MONGOSH=mongosh; # for MongoDB >= 6.0
else
readonly MONGOSH=mongo;
fi;f${MONGOSHMongoDB 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:
- Prerequisites
- Upgrade Preparation
- Upgrade from MongoDB 4.2 to MongoDB 4.4
- Upgrade from MongoDB 4.4 to MongoDB 5.0
- Upgrade from MongoDB 5.0 to MongoDB 6.0
- Services Restart
- 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 | ||
---|---|---|
| ||
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.
...
- Operating System
- MongoDB Version
- MongoDB Storage Engine
- NMIS and Modules for Mongo 6.0
Supported Operating Systems
MongoDB 6.0 is officially supported on the following Debian platforms:
...
|
MongoDB 4.2 Installed and Running
Verify by running (with your mongodb <username> and <password>)
...
|
MongoDB Storage Engine
Verify storage engine by running
...
https://www.mongodb.com/docs/v4.2/tutorial/change-standalone-wiredtiger/
Upgrade NMIS and Modules for MongoDB 6.0
NMIS and Modules must be updated to versions that support MongoDB 6.0 before upgrading to MongoDB 6.0. These releases are backwards compatible with MongoDB v4.2 which means that you can upgrade to NMIS and Modules that support MongoDB 6.0, restart NMIS and Modules, and continue to use them with MongoDB 4.2, then upgrade your MongoDB from 4.2 to 6.0 later.
...
You should follow the standard upgrade process for each of these packages, which is handled by the FirstWave Installer.
Preparation
The preparation phase includes 3 sections
...
This is to be done in this specific sequence.
System Snapshot/Backup
For System Snapshots and Backups you will need to refer to the documentation for your environment.
...
- Full system backups, including Operating System and Data - Contact your IT department, Vendor Support, or Integrator
- Virtual Machine Snapshots - Refer to the solution guides for the environment
- Database Dump - MongoDB documentation: https://www.mongodb.com/docs/database-tools/mongodump/
Upgrade Linux Packages
After completing the snapshot/backup follow Debian's instructions for upgrading and checking the sanity of the apt package system.
...
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.
...
|
Upgrade from MongoDB 4.2 to MongoDB 4.4
Prepare the Database for Upgrade
...
Check the database compatibility mode is set to "4.2"
|
The result should be as follows ensuring that the value 4.2 is set
|
If MongoDB is on version 4.2 and the featureCompatibilityVersion is not "4.2"
|
The result should be as follows ensuring that the value 4.2 is setthen set this with the following command
|
As before, the check the featureCompatibilityVersion again confirming the correct value
Example Command and Output
|
...
Debian - Install MongoDB 4.
...
|
As before, the check the featureCompatibilityVersion again confirming the correct value
Example Command and Output
|
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:
|
...
|
...
|
...
|
...
Commands summarised here:
wget -qO - https://www.mongodb.org/static/pgp/
|
Complete the upgrade with the following commands and retest. If you skip the stop/start sequence above the following command will fail.
|
Upgrade from MongoDB 4.4 to MongoDB 5.0
Prepare the Database for Upgrade
Check the database compatibility mode is set to "4.4"
...
to "4.4"
|
The result should be as follows ensuring that the value 4.4 is set
...
If MongoDB is on version 4.4 and the featureCompatibilityVersion is not "4.4" then set this with the following command
|
As before, the check the featureCompatibilityVersion again confirming the correct value
Example Command and Output
|
As before, the check the featureCompatibilityVersion again confirming the correct value
Example Command and Output
|
Debian - Install MongoDB 5.0 Repo and Upgrade
Details available here:
https://www.mongodb.com/docs/manual/release-notes/5.0-upgrade-standalone/ and https://www.mongodb.com/docs/v5.0/tutorial/install-mongodb-on-debian/
Commands summarised here:
mongo -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval 'db.adminCommand( { setFeatureCompatibilityVersion: "5.0" } )'
mongo -u $YOUR_USERNAME -p $YOUR_PASSWORD --authenticationDatabase=admin --quiet --eval 'db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )'
Fix it by using:
thenFix it by using:
and answer N to keep your currently installed version of /etc/mongod.conf
|
Complete the upgrade with the following commands and retest. If you skip the stop/start sequence above the following command will fail.
then
and answer N to keep your currently installed version of /etc/mongod.conf
|
Complete the upgrade with the following commands and retest. If you skip the stop/start sequence above the following command will fail.
|
...
Example Command and Output
|
Upgrade from MongoDB 5.0 to MongoDB 6.0
Prepare the Database for Upgrade
Check the database compatibility mode is set to "5.0"
...
to "5.0"
|
The result should be as follows ensuring that the value 5.0 is set
|
If MongoDB is on version 5.0 and the featureCompatibilityVersion is not "5.0" then set this with the following command
...
MongoDB is on version 5.0 and the featureCompatibilityVersion is not "5.0"
...
then set this with the following command
|
As before, the check the featureCompatibilityVersion again confirming the correct value
Example Command and Output
...
Output
|
Debian - Install MongoDB 6.0 Repo and Upgrade
Details available here:
https://www.mongodb.com/docs/manual/release-notes/6.0-upgrade-standalone/ and https://www.mongodb.com/docs/v6.0/tutorial/install-mongodb-on-debian/k
Commands summarised here:
|
...
Note that you must now use the mongosh command instead of mongo
|
...
Example Command and Output
|
This completes the in-situ upgrade of MongoDB 4.2 to 6.0 Standalone
Restart All FirstWave Daemons
Now the MongoDB upgrade is complete, you can start all the NMIS and FirstWave daemons.
...
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
...