1. Upgrading MongoDB from version 4.2 to 5.0 is a multi-step process. Before performing any upgrades, it's crucial to back up your MongoDB data.
  2. Test that the upgraded system is working correctly with MongoDB 4.4 before upgrading to MongoDB 5.0.
  3. Stop all API Behavioral Security (ABS), API Publish, and Dashboard components.
  4. Ensure all replica set members are running MongoDB version 4.2.
  5. Ensure the 4.2 replica set has featureCompatibilityVersion set to 4.2:
    1. Connect to each replica set member and check featureCompatibilityVersion using the following command:
      db.adminCommand( { 
      getParameter: 1,
      featureCompatibilityVersion: 1
      } )
    2. To set or update featureCompatibilityVersion, run the following command on the primary:
      db.adminCommand( { setFeatureCompatibilityVersion: "4.2" } )
  6. Ensure that no replica set member is in ROLLBACK or RECOVERING state by running the rs.status() command command in the primary.
  7. Prior to upgrading a member of the replica set, confirm that the member was cleanly shut down.
  8. Make sure that the abs_rs.js file has actual MongoDB IPs (instead of localhost/127.0.0.1) for the replica set members.

To upgrade MongoDB version 4.2 to 5.0:

  1. Upgrade secondary members of the replica set:
    1. Shutdown the secondary mongo instance.
    2. Download the 4.4 mongo build and untar it.
    3. Replace the 4.2 binary with the 4.4 binary.
    4. Restart the member.
  2. To step down the primary and force an election of a new primary, connect a mongod shell to the primary and use rs.stepDown().
  3. When rs.status() shows that the primary has stepped down and another member has assumed PRIMARY state, upgrade the stepped-down primary:
    1. Shut down the stepped-down primary and replace the mongod binary with the 4.4 binary.
    2. Restart the member.
  4. To enable backwards-incompatible 4.4 features, run the setFeatureCompatibilityVersion command on the primary in the admin database:
    db.adminCommand( { setFeatureCompatibilityVersion: "4.4" } )
  5. Repeat the prerequisites and steps 1-4 to upgrade from 4.4.15 to 5.0.18.

Complete the steps in Migrating MongoDB from RHEL 7.9 to 8.