How to Upgrade MongoDB From 4.2 to 6.0
Following security risks in MongoDB 4.2, it was about time to update the version used by Cloudshell.
Disclaimer
The below instructions are for Cloudshell default installation with a standalone MongoDB installation only.
MongoDB does not support Windows Server 2012. For details, see Windows OS requirements.
Prerequisites
- RDP connection to Cloudshell server
- Cloudshell services down time
- Internet access to download all relevant files (can be done in a dedicated server and copied to Cloudshell server)
Getting the files
-
Obtain the following MongoDB official files and place them in a temporary folder (referred to as "Downloads” in this guide) on the Cloudshell server:
-
Enter the Cloudshell server and extract all files.
Upgrade from 4.2 to 4.4
-
Start the MongoDB shell.
- Navigate to
Downloads\mongosh-1.9.0-win32-x64\bin
- Double click the
mongosh.exe
executable. - Follow the instructions to connect to "localhost” (press enter).
- Navigate to
-
Validate dependencies by running in the shell:
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
// Expected response: { version: '4.2' }, ok: 1 -
Get reservation count for reference after upgrade:
- Switch to the Quali database:
use Quali
db.Reservation.countDocuments()
- Switch to the Quali database:
-
Open Task Manager > Services.
-
Stop the Quali Server process.
-
Shut down MongoDB by running:
use admin
db.shutdownServer()
// Expected response: MongoNetworkError: connection 3 to 127.0.0.1:27017 closed
// Then close the shell window -
Navigate to the downloaded 4.4 bin folder in File Explorer:
Downloads\mongodb-win32-x86_64-windows-4.4.22\bin
-
In a separate File Explorer window, open the MongoDB installation's bin folder:
C:\Program Files\MongoDB\Server\4.2\bin
-
Delete the mongod.exe file from C:\Program Files\MongoDB\Server\4.2\bin.
-
Copy the new mongod.exe file from the 4.4\bin folder to C:\Program Files\MongoDB\Server\4.2\bin.
-
Open Task Manager > Services.
-
Start the MongoDB service.
-
Start the MongoDB shell and validate the version:
db.version()
-
(Optional) Start the Quali Server process and check sandboxes.
-
Stop Quali Server (if running).
-
Update MongoDB capabilities:
db.adminCommand({ setFeatureCompatibilityVersion: "4.4" })
Upgrade from 4.4 to 5.0
-
Start the MongoDB shell.
- Navigate to
Downloads\mongosh-1.9.0-win32-x64\bin
- Double click the
mongosh.exe
executable. - Follow the instructions to connect to "localhost” (press enter).
- Navigate to
-
Validate dependencies by running in the shell:
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
// Expected response: { version: '4.4' }, ok: 1 -
Open Task Manager > Services.
-
Stop the Quali Server process.
-
Shut down MongoDB by running:
use admin
db.shutdownServer()
// response should look like: MongoNetworkError: connection 5 to 127.0.0.1:27017 closed
// close the shell window -
Enter the downloaded 5.0 bin folder in File Explorer:
Downloads\mongodb-win32-x86_64-windows-5.0.18\bin
-
In a different File Explorer, open the bin folder of MongoDB installation:
C:\Program Files\MongoDB\Server\4.2\bin
-
Delete the mongod.exe file in C:\Program Files\MongoDB\Server\4.2\bin.
-
Copy the new mongod.exe file from the 5.0.18\bin folder to C:\Program Files\MongoDB\Server\4.2\bin.
-
Open Task Manager > Services.
-
Start the MongoDB service.
-
Start the MongoDB shell.
- Validate version:
db.version()
- Validate reservations are still there:
use Quali
db.Reservation.countDocuments()
- Validate version:
-
(Optional) Start the Quali Server process and enter the Sandboxes dashboard in CloudShell Portal.
-
Stop Quali Server (if running).
-
Update MongoDB capabilities:
db.adminCommand({ setFeatureCompatibilityVersion: "5.0" })
Upgrade from 5.0 to 6.0
-
Start the MongoDB shell.
- Navigate to
Downloads\mongosh-1.9.0-win32-x64\bin
- Double click the
mongosh.exe
executable. - Follow the instructions to connect to "localhost” (press enter).
- Navigate to
-
Validate dependencies by running in the shell:
db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
// Expected response: { version: '5.0' }, ok: 1 -
Open Task Manager > Services.
-
Stop the Quali Server process (if running).
warningFrom this step, there are differences from previous upgrade flows.
-
Shut down mongoDB by running:
- Run
db.adminCommand( { shutdown: 1 } )
// response should look like: MongoNetworkError: connection 5 to 127.0.0.1:27017 closed
// close the shell window
- Run
-
Ensure that the 5.0-series binaries are in your System PATH. To confirm your binary version, run the following command:
- Open command line window.
- Run
mongod --version
- If 'mongod' is not recognized, add the bin folder to the system path:
- Open Environment Variables.
- Under System Variables, locate and select the Path.
- Click Edit.
- Click New.
- Enter
C:\Program Files\MongoDB\Server\4.2\bin
. - Click OK in all windows.
- Open a new command line window and retest.
-
Enter the downloaded 6.0 bin folder in File Explorer:
Downloads\mongodb-win32-x86_64-windows-6.0.6\bin
-
In a different file explorer, open the bin folder of mongoDB installation:
C:\Program Files\MongoDB\Server\4.2\bin
-
Delete the
mongod.exe
file fromC:\Program Files\MongoDB\Server\4.2\bin
. -
Copy the new
mongod.exe
file from the6.0.6\bin
folder toC:\Program Files\MongoDB\Server\4.2\bin
. -
Open Task Manager > Services.
-
Start the MongoDB service.
-
Start the MongoDB shell.
- Validate version:
db.version()
- Validate reservations are still there:
use Quali
db.Reservation.countDocuments()
- Validate version:
-
(Optional) Start Quali Server and enter the Sandboxes dashboard in CloudShell Portal.
-
Stop Quali Server (if running).
-
Update MongoDB capabilities:
db.adminCommand( { setFeatureCompatibilityVersion: "6.0" } )