Upgrade a Replica Set to 4.2
On this page
- Upgrade Recommendations and Checklists
- Read Concern Majority (3-Member Primary-Secondary-Arbiter Architecture)
- Change Stream Resume Tokens
- All Members Version
- MMAPv1 to WiredTiger Storage Engine
- Increase Open Files
ulimit
Setting - Review Current Configuration
- Feature Compatibility Version
- Replica Set Member State
- Via Package Manager
- Manually
Important
Before you attempt any upgrade, please familiarize yourself with the content of this document.
If you need guidance on upgrading to 4.2, 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 4.2, you must be running a 4.0-series release.
To upgrade from a version earlier than the 4.0-series, you must successively upgrade major releases until you have upgraded to 4.0-series. For example, if you are running a 3.6-series, you must upgrade first to 4.0 before you can upgrade to 4.2.
Check Driver Compatibility
Before you upgrade MongoDB, check that you're using a MongoDB 4.2-compatible driver. Consult the driver documentation for your specific driver to verify compatibility with MongoDB 4.2.
Upgraded deployments that run on incompatible drivers might encounter unexpected or undefined behavior.
Preparedness
Before beginning your upgrade, see the Compatibility Changes in MongoDB 4.2 document to ensure that your applications and deployments are compatible with MongoDB 4.2. 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.2, if you need to downgrade, we recommend downgrading to the latest patch release of 4.0.
Read Concern Majority (3-Member Primary-Secondary-Arbiter Architecture)
Starting in MongoDB 3.6, MongoDB enables support for
"majority"
read concern by default.
You can disable read concern "majority"
to prevent the
storage cache pressure from immobilizing a three-member replica set
with a primary-secondary-arbiter (PSA) architecture or a sharded
cluster with a three-member PSA shards.
Note
Disabling "majority"
read concern affects support for
transactions on sharded clusters. Specifically:
A transaction cannot use read concern
"snapshot"
if the transaction involves a shard that has disabled read concern "majority".A transaction that writes to multiple shards errors if any of the transaction's read or write operations involves a shard that has disabled read concern
"majority"
.
However, it does not affect transactions
on replica sets. For transactions on replica sets, you can specify
read concern "majority"
(or "snapshot"
or "local"
) for multi-document transactions even if
read concern "majority"
is disabled.
Disabling "majority"
read concern prevents
collMod
commands which modify an index from
rolling back. If such an operation needs
to be rolled back, you must resync the affected nodes with the
primary node.
Disabling "majority"
read concern has no effect on change
streams availability.
When upgraded to 4.2 with read concern "majority" disabled, you can use change streams for your deployment.
For more information, see Primary-Secondary-Arbiter Replica Sets.
Change Stream Resume Tokens
MongoDB 4.2 uses the version 1 (i.e. v1
) change streams
resume tokens, introduced in
version 4.0.7.
The resume token _data
type depends on the MongoDB versions and,
in some cases, the feature compatibility version (fcv) at the time
of the change stream's opening/resumption (i.e. a change in fcv
value does not affect the resume tokens for already opened change
streams):
MongoDB Version | Feature Compatibility Version | Resume Token _data Type |
---|---|---|
MongoDB 4.2 and later | "4.2" or "4.0" | Hex-encoded string ( v1 ) |
MongoDB 4.0.7 and later | "4.0" or "3.6" | Hex-encoded string ( v1 ) |
MongoDB 4.0.6 and earlier | "4.0" | Hex-encoded string ( v0 ) |
MongoDB 4.0.6 and earlier | "3.6" | BinData |
MongoDB 3.6 | "3.6" | BinData |
Important
When upgrading from MongoDB 4.0.6 or earlier to MongoDB 4.2
During the upgrade process, a client may try to resume change
streams using the new v1
resume token when connected to a member
that has not been updated (i.e. only accepts v0
token) and
fail. In such cases, the client must wait for the 4.2
upgrade to complete before resuming change streams.
Prerequisites
All Members Version
All replica set members must be running version 4.0. To upgrade a replica set from an 3.6-series and earlier, first upgrade all members of the replica set to the latest 4.0-series release, and then follow the procedure to upgrade from MongoDB 4.0 to 4.2.
MMAPv1 to WiredTiger Storage Engine
MongoDB 4.2 removes support for the deprecated MMAPv1 storage engine.
If your 4.0 deployment uses MMAPv1, you must change the 4.0 deployment to WiredTiger Storage Engine before upgrading to MongoDB 4.2. For details, see Change Replica Set to WiredTiger.
Increase Open Files ulimit
Setting
Starting in MongoDB 4.2, incoming connections to a mongod
or
mongos
instance require two file descriptors. In previous
versions of MongoDB, incoming connections required one file
descriptor.
Prior to upgrading from MongoDB 4.0 to 4.2, you may need to increase the
value of your open files ulimit setting (-n
).
Review Current Configuration
With MongoDB 4.2, the mongod
and
mongos
processes will not start with
MMAPv1 Specific Configuration Options. Previous versions of MongoDB running
WiredTiger ignored MMAPv1 configurations options if they were specified.
With MongoDB 4.2, you must remove these from your configuration.
Feature Compatibility Version
The 4.0 replica set must have
featureCompatibilityVersion
set to 4.0
.
To ensure that all members of the replica set have
featureCompatibilityVersion
set to 4.0
, 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.0" }
.
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.0" } )
For more information, see
setFeatureCompatibilityVersion
.
Replica Set Member State
Ensure that no replica set member is in ROLLBACK
or
RECOVERING
state.
Download 4.2 Binaries
Via Package Manager
If you installed MongoDB from the MongoDB apt
, yum
, dnf
, or
zypper
repositories, you should upgrade to 4.2 using your package
manager.
Follow the appropriate 4.2 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 4.2 installation instructions for more information.
Upgrade Process
You can upgrade from MongoDB 4.0 to 4.2 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 a mongo
shell 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 4.2 binary.Restart the member.
Enable backwards-incompatible 4.2 features.
At this point, you can run the 4.2 binaries without the 4.2 features that are incompatible with 4.0.
To enable these 4.2 features, set the feature compatibility
version (FCV
) to 4.2.
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.2" } )
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.
Post Upgrade
TLS
Options Replace DeprecatedSSL
Options- Starting in MongoDB 4.2, MongoDB deprecates the SSL options for the
mongod, the mongos, and the
mongo
shell as well as the correspondingnet.ssl
Options configuration file options.To avoid deprecation messages, use the newTLS
options for the mongod, the mongos, and themongo
.For the command-line TLS options, refer to the mongod, mongos, and
mongo
shell pages.For the corresponding
mongod
andmongos
configuration file options, refer to the configuration file page.For the connection string
tls
options, refer to the connection string page.
- 4.2+ compatible Drivers Retry Writes by Default
- Drivers compatible with MongoDB 4.2 and higher enable
Retryable Writes by default. Earlier drivers require the
retryWrites=true
option. TheretryWrites=true
option can be omitted in applications that use drivers compatible with MongoDB 4.2 and higher.To disable retryable writes, applications that use drivers compatible with MongoDB 4.2 and higher must includeretryWrites=false
in the connection string.
Additional Upgrade Procedures
To upgrade a standalone, see Upgrade a Standalone to 4.2.
To upgrade a sharded cluster, see Upgrade a Sharded Cluster to 4.2.