Docs Menu
Docs Home
/
MongoDB Manual
/ / /

Upgrade a Sharded Cluster to 7.0

On this page

  • Upgrade Recommendations and Checklists
  • Prerequisites
  • Download 7.0 Binaries
  • Upgrade Procedure
  • Additional Upgrade Procedures

Use this tutorial to upgrade from MongoDB 6.0 to MongoDB 7.0. To upgrade to a new patch release within the same release series, see Upgrade to the Latest Self-Managed Patch Release of MongoDB.

Familiarize yourself with the content of this document, including thoroughly reviewing the prerequisites, prior to upgrading to MongoDB 7.0.

The following steps outline the procedure to upgrade a mongod that is a shard member from version 6.0 to 7.0.

If you need guidance on upgrading to 7.0, MongoDB professional services offer major version upgrade support to help ensure a smooth transition without interruption to your MongoDB application.

When upgrading, consider the following:

To upgrade an existing MongoDB deployment to 7.0, you must be running a 6.0-series release.

To upgrade from a version earlier than the 6.0-series, you must successively upgrade major releases until you have upgraded to 6.0-series. For example, if you are running a 5.0-series, you must upgrade first to 6.0 before you can upgrade to 7.0.

Before you upgrade MongoDB, check that you're using a MongoDB 7.0-compatible driver. Consult the driver documentation for your specific driver to verify compatibility with MongoDB 7.0.

Upgraded deployments that run on incompatible drivers might encounter unexpected or undefined behavior.

Before beginning your upgrade, see the Compatibility Changes in MongoDB 7.0 document to ensure that your applications and deployments are compatible with MongoDB 7.0. Resolve the incompatibilities in your deployment before starting the upgrade.

Before upgrading MongoDB, always test your application in a staging environment before deploying the upgrade to your production environment.

Starting in MongoDB 7.0, you cannot downgrade your deployment's binary version without assistance from support.

To learn more, see Downgrade 7.0 to 6.0.

To upgrade a sharded cluster to 7.0, all members of the cluster must be at least version 6.0. The upgrade process checks all components of the cluster and will produce warnings if any component is running version earlier than 6.0.

The 6.0 sharded cluster must have featureCompatibilityVersion set to "6.0".

To ensure that all members of the sharded cluster have featureCompatibilityVersion set to "6.0", connect to each shard replica set member and each config server replica set member and check the featureCompatibilityVersion:

Tip

For a sharded cluster that has access control enabled, to run the following command against a shard replica set member, you must connect to the member as a shard local user.

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

All members should return a result that includes "featureCompatibilityVersion" : { "version" : "6.0" }.

To set or update featureCompatibilityVersion, run the following command on the mongos:

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

For more information, see setFeatureCompatibilityVersion.

For shards and config servers, ensure that no replica set member is in the ROLLBACK or RECOVERING state.

db.adminCommand( { replSetGetStatus: 1 } )

Optional but Recommended. As a precaution, take a backup of the config database before upgrading the sharded cluster.

If you installed MongoDB from the MongoDB apt, yum, dnf, or zypper repositories, you should upgrade to 7.0 using your package manager.

Follow the appropriate 7.0 installation instructions for your Linux system. This will involve adding a repository for the new release, then performing the actual upgrade process.

If you have not installed MongoDB using a package manager, you can manually download the MongoDB binaries from the MongoDB Download Center.

See 7.0 installation instructions for more information.

1

Connect mongosh to a mongos instance in the sharded cluster, and run sh.stopBalancer() to disable the balancer:

sh.stopBalancer()

Note

If a migration is in progress, the system will complete the in-progress migration before stopping the balancer. You can run sh.isBalancerRunning() to check the balancer's current state.

To verify that the balancer is disabled, run sh.getBalancerState(), which returns false if the balancer is disabled:

sh.getBalancerState()

For more information on disabling the balancer, see Disable the Balancer.

2
  1. Upgrade the secondary members of the replica set, one at a time.

    1. Shut down the secondary instance.

      To shut down the mongod process, use mongosh to connect to the cluster member and run the following command:

      db.adminCommand( { shutdown: 1 } )
    2. Replace the 6.0 binary with the 7.0 binary.

    3. Start the 7.0 binary.

      Start the 7.0 binary with the --configsvr, --replSet, and --port. Include any other options as used by the deployment.

      mongod --configsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address>

      If using a configuration file, update the file to specify sharding.clusterRole: configsvr, replication.replSetName, net.port, and net.bindIp, then start the 7.0 binary:

      sharding:
      clusterRole: configsvr
      replication:
      replSetName: <string>
      net:
      port: <port>
      bindIp: localhost,<ip address>
      storage:
      dbpath: <path>

      Include any other settings as appropriate for your deployment.

    4. Wait for the member to recover to the SECONDARY state before upgrading the next secondary member.

      To check the member's state, issue rs.status() in mongosh.

    5. Repeat for each secondary member.

  2. Step down the replica set primary.

    1. Step down the primary.

      Connect mongosh to the primary and use rs.stepDown() to step down the primary and force an election of a new primary:

      rs.stepDown()
    2. Shut down the stepped-down primary.

      When rs.status() shows that the primary has stepped down and another member has assumed the PRIMARY state, shut down the stepped-down primary.

      To shut down the stepped-down primary, use mongosh to connect to the primary and run the following command:

      db.adminCommand( { shutdown: 1 } )
    3. Replace the mongod binary with the 7.0 binary.

    4. Start the 7.0 binary.

      Start the 7.0 with the --configsvr, --replSet, --port, and --bind_ip options. Include any optional command line options used by the previous deployment:

      mongod --configsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address>

      If using a configuration file, update the file to specify sharding.clusterRole: configsvr, replication.replSetName, net.port, and net.bindIp, then start the 7.0 binary:

      sharding:
      clusterRole: configsvr
      replication:
      replSetName: <string>
      net:
      port: <port>
      bindIp: localhost,<ip address>
      storage:
      dbpath: <path>

      Include any other configuration as appropriate for your deployment.

3

Upgrade the shards one at a time.

For each shard replica set:

  1. Upgrade the secondary members of the replica set, one at a time.

    1. Shut down the secondary instance.

      To shut down the mongod process, use mongosh to connect to the cluster member and run the following command:

      db.adminCommand( { shutdown: 1 } )
    2. Replace the 6.0 binary with the 7.0 binary.

      Start the 7.0 binary with the --shardsvr, --replSet, --port, and --bind_ip options. Include any additional command line options as appropriate for your deployment:

      mongod --shardsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address>

      If using a configuration file, update the file to include sharding.clusterRole: shardsvr, replication.replSetName, net.port, and net.bindIp, then start the 7.0 binary:

      sharding:
      clusterRole: shardsvr
      replication:
      replSetName: <string>
      net:
      port: <port>
      bindIp: localhost,<ip address>
      storage:
      dbpath: <path>

      Include any other configuration as appropriate for your deployment.

    3. Wait for the member to recover to the SECONDARY state before upgrading the next secondary member.

      To check the member's state, you can issue rs.status() in mongosh.

    4. Repeat for each secondary member.

  2. Step down the replica set primary.

    Connect mongosh to the primary and use rs.stepDown() to step down the primary and force an election of a new primary:

    rs.stepDown()
  3. Upgrade the stepped-down primary.

    When rs.status() shows that the primary has stepped down and another member has assumed the PRIMARY state, upgrade the stepped-down primary:

    1. Shut down the stepped-down primary.

      To shut down the stepped-down primary, use mongosh to connect to the replica set member and run the following command:

      db.adminCommand( { shutdown: 1 } )
    2. Replace the mongod binary. with the 7.0 binary.

    3. Start the 7.0 binary.

      Start the 7.0 binary with the --shardsvr, --replSet, --port, and --bind_ip options. Include any additional command line options as appropriate for your deployment:

      mongod --shardsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address>

      If using a configuration file, update the file to specify sharding.clusterRole: shardsvr, replication.replSetName, net.port, and net.bindIp, then start the 7.0 binary:

      sharding:
      clusterRole: shardsvr
      replication:
      replSetName: <string>
      net:
      port: <port>
      bindIp: localhost,<ip address>
      storage:
      dbpath: <path>

      Include any other configuration as appropriate for your deployment.

4

Replace each mongos instance with the 7.0 binary and restart. Include any other configuration as appropriate for your deployment.

Note

The --bind_ip option must be specified when the sharded cluster members are run on different hosts or if remote clients connect to the sharded cluster.

mongos --configdb csReplSet/<rsconfigsver1:port1>,<rsconfigsver2:port2>,<rsconfigsver3:port3> --bind_ip localhost,<ip address>
5

Using mongosh, connect to a mongos in the cluster and run sh.startBalancer() to re-enable the balancer:

sh.startBalancer()

For more information about re-enabling the balancer, see Enable the Balancer.

6

At this point, you can run the 7.0 binaries without the 7.0 features that are incompatible with 6.0.

To enable these 7.0 features, set the feature compatibility version (FCV) to 7.0.

Tip

Enabling these backwards-incompatible features can complicate the downgrade process since you must remove any persisted backwards-incompatible features before you downgrade.

It is recommended that after upgrading, you allow your deployment to run without enabling these features for a burn-in period to ensure the likelihood of downgrade is minimal. When you are confident that the likelihood of downgrade is minimal, enable these features.

On a mongos instance, run the setFeatureCompatibilityVersion command in the admin database:

db.adminCommand( { setFeatureCompatibilityVersion: "7.0", confirm: true } )

Setting featureCompatibilityVersion (FCV) : "7.0" implicitly performs a replSetReconfig on each shard to add the term field to the shard replica configuration document.

The command doesn't complete until the new configuration propagates to a majority of replica set members.

This command must perform writes to an internal system collection. If for any reason the command does not complete successfully, you can safely retry the command on the mongos as the operation is idempotent.

Note

While setFeatureCompatibilityVersion is running on the sharded cluster, chunk migrations, splits, and merges can fail with ConflictingOperationInProgress.

Any orphaned documents that exist on your shards will be cleaned up when you set the setFeatureCompatibilityVersion to 7.0. The cleanup process:

  • Does not block the upgrade from completing, and

  • Is rate limited. To mitigate the potential effect on performance during orphaned document cleanup, see Range Deletion Performance Tuning.

Warning

mongos FCV Compatibility

The mongos binary cannot connect to mongod instances whose feature compatibility version (FCV) is greater than that of the mongos. For example, you cannot connect a MongoDB 6.0 version mongos to a 7.0 sharded cluster with FCV set to 7.0. You can, however, connect a MongoDB 6.0 version mongos to a 7.0 sharded cluster with FCV set to 6.0.

Back

Replica Set