Navigation

Upgrade a Replica Set to 4.0

Important

MongoDB 4.0 may lose data during unclean shutdowns on macOS 10.13+.

For details, see WT-4018.

Important

Before you attempt any upgrade, please familiarize yourself with the content of this document.

If you need guidance on upgrading to 4.0, MongoDB offers major version upgrade services to help ensure a smooth transition without interruption to your MongoDB application.

Upgrade Recommendations and Checklists

When upgrading, consider the following:

Upgrade Version Path

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

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

Preparedness

Before beginning your upgrade, see the Compatibility Changes in MongoDB 4.0 document to ensure that your applications and deployments are compatible with MongoDB 4.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.

Downgrade Consideration

Once upgraded to 4.0, if you need to downgrade, we recommend downgrading to the latest patch release of 3.6.

Initial Syncs

Before starting the upgrade, ensure that no initial sync is in progress. Performing the upgrade while an initial sync is in progress will cause the initial sync to restart.

Default Bind to Localhost

The following procedure includes the command-line option --bind_ip or the configuration option net.bindIp when restarting the replica set.

Starting in MongoDB 3.6, the options must be specified when the replica set members are run on different hosts or if remote clients connect to the deployment. Omit if all members are run on the same host and all clients are local to the host.

Warning

Before you bind to other ip addresses, consider enabling access control and other security measures listed in Security Checklist to prevent unauthorized access.

Prerequisites

All Members Version

All replica set members must be running version 3.6. To upgrade a replica set from an 3.4-series and earlier, first upgrade all members of the replica set to the latest 3.6-series release, and then follow the procedure to upgrade from MongoDB 3.6 to 4.0.

Remove Support for MONGODB-CR

Starting in version 4.0, MongoDB removes support for the deprecated MongoDB Challenge-Response (MONGODB-CR) authentication mechanism.

If your deployment has user credentials stored in MONGODB-CR schema, you must upgrade to Salted Challenge Response Authentication Mechanism (SCRAM) before you upgrade to version 4.0. For information on upgrading to SCRAM, see Upgrade to SCRAM.

Remove pv0 for Replica Sets

Starting in version 4.0, MongoDB removes the deprecated replica set protocol version 0 pv0.

Before upgrading to MongoDB 4.0, you must upgrade to pv1.

To upgrade to pv1, connect a mongo shell to the replica set primary and perform the following sequence of operations:

cfg = rs.conf();
cfg.protocolVersion=1;
rs.reconfig(cfg);

To reduce the likelihood of w:1 rollbacks, you can also reconfigure the replica set to a higher settings.catchUpTimeoutMillis setting.

For more information on pv1, see Replica Set Protocol Version.

Remove Master-Slave Replication

MongoDB 4.0 removes support for the deprecated master-slave replication. Before you can upgrade to MongoDB 4.0, if your deployment uses master-slave replication, you must upgrade to a replica set.

To convert your master-slave replication, see Convert a Master-Slave Deployment to a Replica Set.

Remove Support for $isolated

MongoDB drops support for the $isolated operator. If you have an existing partial index that includes the $isolated operator or a view that includes a $isolated operator, recreate the index or view without the operator in the definition before upgrading.

Feature Compatibility Version

The 3.6 replica set must have featureCompatibilityVersion set to 3.6.

To ensure that all members of the replica set have featureCompatibilityVersion set to 3.6, connect to each replica set member and check the featureCompatibilityVersion:

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

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

To set or update featureCompatibilityVersion, run the following command on the primary. A majority of the data-bearing members must be available:

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

For more information, see setFeatureCompatibilityVersion.

Replica Set Member State

Ensure that no replica set member is in ROLLBACK or RECOVERING state.

Download 4.0 Binaries

Via Package Manager

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

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

Manually

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

See Install MongoDB for more information.

Upgrade Process

You can upgrade from MongoDB 3.6 to 4.0 using a “rolling” upgrade to minimize downtime by upgrading the members individually while the other members are available.

1

Upgrade secondary members of the replica set.

Upgrade the secondary members of the replica set one at a time:

  1. Shut down the mongod instance and replace the 3.6 binary with the 4.0 binary.

  2. Restart the member.

    Note

2

Step down the replica set primary.

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

3

Upgrade the primary.

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.0 binary.

  2. Restart the member.

    Note

4

Enable backwards-incompatible 4.0 features.

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

To enable these 4.0 features, set the feature compatibility version (FCV) to 4.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.

Tip

Ensure that no initial sync is in progress. Running setFeatureCompatibilityVersion command while an initial sync is in progress will cause the initial sync to restart.

On the primary, run the setFeatureCompatibilityVersion command in the admin database:

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

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 primary as the operation is idempotent.

Additional Upgrade Procedures