Upgrade MongoDB from Version 5 to 7 on Windows Server

How to Upgrade MongoDB from Version 5 to 7 on Windows Server โ€“ A Step-by-Step Guide



Introduction:

Upgrading MongoDB is essential for getting new features, performance improvements, and security updates. In this guide, we will upgrade MongoDB from version 5 to version 7 on a Windows Server. This process will cover upgrading from version 5 to 6, and then from 6 to 7, as MongoDB doesn't support direct upgrades from 5 to 7.

Pre-Upgrade Checklist

Before starting the upgrade, ensure the following steps are completed:

  1. Review Release notes

    First always review the MongoDB release notes to see any breaking changes or deprecated features

  2. Backup Your Data: Always create a backup of your MongoDB data using the mongodump command.
  3. mongodump --out /path/to/backup
  4. Check Feature Compatibility Version (FCV): MongoDB uses featureCompatibilityVersion to ensure compatibility with new releases.

    • For MongoDB 5.0, the FCV must be set to "5.0" before upgrading to version 6.
    • For MongoDB 6.0, the FCV must be set to "6.0" before upgrading to version 7.
  5. To check the current featureCompatibilityVersion, run:

    db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })

    The output should include:

    { "featureCompatibilityVersion" : { "version" : "5.0" } }

    If you need to set the FCV, use:

    db.adminCommand({ setFeatureCompatibilityVersion: "5.0" })
  6. Check Application and Driver Compatibility: Make sure your application and drivers are compatible with MongoDB 6 and 7.

  7. Plan for Downtime: Prepare for downtime during the upgrade process.

  8. Check Environment Variables: Ensure your environment variables for MongoDB (e.g., PATH) are properly set. If not, you will need to navigate directly to the MongoDB installation folder.

Step 1: Upgrade from MongoDB 5 to 6

  1. Stop the MongoDB Service: Stop the MongoDB service via the Windows Services tool or using the command:
  2. net stop MongoDB
  3. Verify Feature Compatibility Version: Before upgrading, confirm the featureCompatibilityVersion is set to 5.0 by running:
  4. db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })

    If itโ€™s not set, update it using:

    db.adminCommand({ setFeatureCompatibilityVersion: "5.0" })
  5. Download and Install MongoDB 6: Download MongoDB 6 from the official website and install it following the setup wizard.

  6. Start the MongoDB Service: After installation, restart the MongoDB service using:
  7. net start MongoDB
  8. Verify the Upgrade: Open the MongoDB shell and verify the version:
  9. mongo
    db.version()

Step 2: Upgrade from MongoDB 6 to 7

  1. Stop the MongoDB Service: Stop MongoDB using the same method as in Step 1.

  2. Verify Feature Compatibility Version: Before upgrading, confirm the feature-compatibility version is set to 6.0 by running:
  3. db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })

    If necessary, update the FCV using:

    db.adminCommand({ setFeatureCompatibilityVersion: "6.0" })
  4. Download and Install MongoDB 7: Download and install MongoDB 7 from the official website.

  5. Start the MongoDB Service: Restart the MongoDB service:
  6. net start MongoDB
  7. Verify the Upgrade: Open the MongoDB shell and check the version:
  8. mongo
    db.version()

Post-Upgrade Steps

  1. Set Feature Compatibility Version to 7.0: Once MongoDB 7 is running, set the feature-compatibility version to 7.0:
  2. db.adminCommand({ setFeatureCompatibilityVersion: "7.0" })
  3. Monitor Performance: Regularly check MongoDB performance and logs to ensure everything is running smoothly.

  4. Test Applications: Make sure your applications are functioning as expected with MongoDB 7.

Comments

Looking for Database Consulting?

Get expert help with Oracle, PostgreSQL, and MongoDB services.

Contact US