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 instruction are for Cloudshell default installation with a standalone MongoDB installation only.
Note: 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 in a temporary folder (referred as “Downloads” in this guide) in Cloudshell server:
- Enter the Cloudshell server and extract all files.
Upgrade from 4.2 to 4.4
- Start the MongoDB shell:
Run:
cd to Downloads\mongosh-1.9.0-win32-x64\bin
- Double click the mongosh.exe executable
- Follow the instructions to connect to “localhost”
-
Validate dependencies by running in the shell:
db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ) response must be as follow: { version: '4.2' }, ok: 1
- get reservation count for reference after upgrade:
- use Quali
db.Reservation.countDocuments()
- Open Task Manager > Services.
- Stop the Quali Server process.
-
Shut down mongoDB by running:
use admin db.shutdownServer() response should look like: MongoNetworkError: connection 3 to 127.0.0.1:27017 closed close the shell window
-
Enter the downloaded 4.4 bin folder in File Explorer:
Downloads\mongodb-win32-x86_64-windows-4.4.22\bin
-
In a different File Explorer, 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:
validate version - db.version()
- (Optional) Start the Quali Server process and make sure sandboxes are there.
- Stop Quali Server (if running).
-
Update MongoDB capabilities:
db.adminCommand( { setFeatureCompatibilityVersion: "4.4" } )
Upgrade from 4.4 to 5.0
-
Start the MongoDB shell:
-
Run
cd to Downloads\mongosh-1.9.0-win32-x64\bin
- Double click the mongosh.exe executable.
-
- Follow the instructions to connect to “localhost” (press enter).
-
Validate dependencies by running in the shell:
db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ) response must as follow: { 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 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()
-
- (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.
Run:
enter your text here
- Double click the mongosh.exe executable.
- follow the instructions to connect to “localhost” (press enter).
-
validate dependencies by running in the shell:
enter your text here
response must as follow: { version: '5.0' }, ok: 1
- Open Task Manager > Services.
-
Stop the Quali Server process (if running).
Note: From 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 4 to 127.0.0.1:27017 closed
- Close the shell window.
-
- 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:
mongod --version
If 'mongod' is not recognized, add the bin folder to 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 bin folder of mongoDB installation:
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 6.0.6\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()
-
- (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" } )