Upgrade a Replica Set to 5.0
On this page
Use this tutorial to upgrade from MongoDB 4.4 to MongoDB 5.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 5.0.
The following steps outline the procedure to upgrade a
mongod
that is a replica set member from version
4.4 to 5.0.
If you need guidance on upgrading to 5.0, MongoDB professional services offer major version upgrade support 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 5.0, you must be running a 4.4-series release.
To upgrade from a version earlier than the 4.4-series, you must successively upgrade major releases until you have upgraded to 4.4-series. For example, if you are running a 4.2-series, you must upgrade first to 4.4 before you can upgrade to 5.0.
Check Driver Compatibility
Before you upgrade MongoDB, check that you're using a MongoDB 5.0-compatible driver. Consult the driver documentation for your specific driver to verify compatibility with MongoDB 5.0.
Upgraded deployments that run on incompatible drivers might encounter unexpected or undefined behavior.
Preparedness
Before beginning your upgrade, see the Compatibility Changes in MongoDB 5.0 document to ensure that your applications and deployments are compatible with MongoDB 5.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
You cannot downgrade your deployment's binary version without assistance from support.
To learn more, see Downgrade 8.0 to 7.0.
Prerequisites
Before you upgrade your replica set, check the 5.0 Performance Considerations for any potential performance impacts when upgrading to 5.0.
Ensure TTL Config is Valid
Ensure that the TTL configuration is valid.
Before upgrading, remove or correct any TTL indexes that have
expireAfterSeconds
set to NaN
. In MongoDB 5.0 and later,
setting expireAfterSeconds
to NaN
has the same effect as
setting expireAfterSeconds
to 0
. For details, see
TTL expireAfterSeconds
Behavior When Set to NaN
.
All Members Version
All replica set members must be running version 4.4. To upgrade a replica set from an 4.2-series and earlier, first upgrade all members of the replica set to the latest 4.4-series release and then follow the procedure to upgrade from MongoDB 4.4 to 5.0.
Confirm Clean Shutdown
Prior to upgrading a member of the replica set, confirm that the member was cleanly shut down.
Feature Compatibility Version
The 4.4 replica set must have
featureCompatibilityVersion
set to "4.4"
.
To ensure that all members of the replica set have
featureCompatibilityVersion
set to "4.4"
, 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" : "4.4" }
.
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: "4.4" } )
For more information, see
setFeatureCompatibilityVersion
.
Replica Set Member State
Ensure that no replica set member is in ROLLBACK
or
RECOVERING
state.
Download 5.0 Binaries
Via Package Manager
If you installed MongoDB from the MongoDB apt
, yum
, dnf
, or
zypper
repositories, you should upgrade to 5.0 using your package
manager.
Follow the appropriate 5.0 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 5.0 installation instructions for more information.
Upgrade Process
You can upgrade from MongoDB 4.4 to 5.0 using a "rolling" upgrade to minimize downtime by upgrading the members individually while the other members are available.
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.
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:
Shut down the stepped-down primary and replace the
mongod
binary with the 5.0 binary.Restart the member.
Enable backwards-incompatible 5.0 features.
At this point, you can run the 5.0 binaries without the 5.0 features that are incompatible with 4.4.
To enable these 5.0 features, set the feature compatibility
version (fCV
) to 5.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: "5.0" } )
Setting featureCompatibilityVersion (fCV) : "5.0"
implicitly performs a replSetReconfig
to add the
term
field to the configuration document and blocks
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 primary as the operation is idempotent.
Additional Upgrade Procedures
To upgrade a standalone, see Upgrade a Standalone to 5.0.
To upgrade a sharded cluster, see Upgrade a Sharded Cluster to 5.0.