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

  1. Obtain the following MongoDB official files and place in a temporary folder (referred as “Downloads” in this guide) in Cloudshell server:

  1. Enter the Cloudshell server and extract all files.

Upgrade from 4.2 to 4.4

  1. Start the MongoDB shell:
    1. Run:

      cd to Downloads\mongosh-1.9.0-win32-x64\bin
    2. Double click the mongosh.exe executable
    3. Follow the instructions to connect to “localhost”
  2. Validate dependencies by running in the shell:

    db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
    response must be as follow: { version: '4.2' }, ok: 1
  1. get reservation count for reference after upgrade:
    1. use Quali
    2. db.Reservation.countDocuments()
  2. Open Task Manager > Services.
  3. Stop the Quali Server process.
  4. 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
  1. Enter the downloaded 4.4 bin folder in File Explorer:

    Downloads\mongodb-win32-x86_64-windows-4.4.22\bin
  2. In a different File Explorer, open the mongoDB installation's bin folder:

    C:\Program Files\MongoDB\Server\4.2\bin
  3. Delete the mongod.exe file from C:\Program Files\MongoDB\Server\4.2\bin.
  4. Copy the new mongod.exe file from the 4.4\bin folder to C:\Program Files\MongoDB\Server\4.2\bin.
  5. Open Task Manager > Services.
  6. Start the MongoDB service.
  7. Start the MongoDB shell:

    validate version - db.version()
  8. (Optional) Start the Quali Server process and make sure sandboxes are there.
  9. Stop Quali Server (if running).
  10. Update MongoDB capabilities:

    db.adminCommand( { setFeatureCompatibilityVersion: "4.4" } )

Upgrade from 4.4 to 5.0

  1. Start the MongoDB shell:

    1. Run

      cd to Downloads\mongosh-1.9.0-win32-x64\bin
      
    2. Double click the mongosh.exe executable.
  2. Follow the instructions to connect to “localhost” (press enter).
  3. Validate dependencies by running in the shell:

    db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
    response must as follow: { version: '4.4' }, ok: 1
  4. Open Task Manager > Services.
  5. Stop the Quali Server process.
  6. 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
  7. Enter the downloaded 5.0 bin folder in File Explorer:

    Downloads\mongodb-win32-x86_64-windows-5.0.18\bin
  8. In a different File Explorer, open bin folder of mongoDB installation:

    C:\Program Files\MongoDB\Server\4.2\bin
  9. Delete the mongod.exe file in C:\Program Files\MongoDB\Server\4.2\bin
  10. Copy the new mongod.exe file from the 5.0.18\bin folder to C:\Program Files\MongoDB\Server\4.2\bin
  11. Open Task Manager > Services.
  12. Start the MongoDB service.
  13. Start the MongoDB shell.

    1. validate version:

      db.version()
    2. Validate reservations are still there:

      use Quali
      db.Reservation.countDocuments()
  14. (Optional) Start the Quali Server process and enter the Sandboxes dashboard in CloudShell Portal.
  15. Stop Quali Server (if running).
  16. Update MongoDB capabilities:

    db.adminCommand( { setFeatureCompatibilityVersion: "5.0" } )

Upgrade from 5.0 to 6.0

  1. Start the MongoDB shell.
    1. Run:

      enter your text here
    2. Double click the mongosh.exe executable.
    3. follow the instructions to connect to “localhost” (press enter).
  2. validate dependencies by running in the shell:

    enter your text here

    response must as follow: { version: '5.0' }, ok: 1

  3. Open Task Manager > Services.
  4. Stop the Quali Server process (if running).

    Note: From this step there are differences from previous upgrade flows.

  5. Shut down mongoDB by running:

    1. Run:

      db.adminCommand( { shutdown: 1 } )

      Response should look like: MongoNetworkError: connection 4 to 127.0.0.1:27017 closed

    2. Close the shell window.
  6. Ensure that the 5.0-series binaries are in your System PATH. To confirm your binary version, run the following command:
    1. Open command line window:

      mongod --version
    2. If 'mongod' is not recognized, add the bin folder to system path:

      1. Open Environment Variables.
      1. Under System Variables, locate and select the Path.
      2. Click Edit.
      3. Click New.
      4. enter C:\Program Files\MongoDB\Server\4.2\bin.
      5. Click OK in all windows.
      6. Open a new command line window and retest.
  7. Enter the downloaded 6.0 bin folder in File Explorer:

    Downloads\mongodb-win32-x86_64-windows-6.0.6\bin
  8. in a different file explorer open bin folder of mongoDB installation:

    C:\Program Files\MongoDB\Server\4.2\bin
  9. Delete the mongod.exe file from C:\Program Files\MongoDB\Server\4.2\bin.
  10. Copy the new mongod.exe file from the 6.0.6\bin folder to C:\Program Files\MongoDB\Server\4.2\bin.
  11. Open Task Manager > Services.
  12. Start the MongoDB service.
  13. Start the MongoDB shell.

    1. validate version:

      db.version()
    2. Validate reservations are still there:

      use Quali
      db.Reservation.countDocuments()
  14. (Optional) Start Quali Server and enter the Sandboxes dashboard in CloudShell Portal.
  15. Stop Quali Server (if running).
  16. Update MongoDB capabilities:

    db.adminCommand( { setFeatureCompatibilityVersion: "6.0" } )

Related Topics