- Release Notes >
- Release Notes for MongoDB 4.2 >
- Downgrade 4.2 to 4.0 >
- Downgrade 4.2 Standalone to 4.0
Downgrade 4.2 Standalone to 4.0¶
On this page
Before you attempt any downgrade, familiarize yourself with the content of this document.
Downgrade Path¶
Once upgraded to 4.2, if you need to downgrade, we recommend downgrading to the latest patch release of 4.0.
Tip
If you downgrade,
- On Windows, downgrade to version 4.0.12 or later version. You cannot downgrade to a 4.0.11 or earlier version.
- On Linux/macOS, if you are running change streams and want to seamlessly resume change streams, downgrade to 4.0.7 or later versions.
Create Backup¶
Optional but Recommended. Create a backup of your database.
Access Control¶
If your deployment has access control enabled, your downgrade user
privileges must include privileges to list and manage indexes across
databases. A user with root
role has the required privileges.
Prerequisites¶
To downgrade from 4.2 to 4.0, you must remove incompatible features that are persisted and/or update incompatible configuration settings. These include:
1. Downgrade Feature Compatibility Version (fCV)¶
To downgrade the featureCompatibilityVersion
of your sharded
cluster:
Downgrade the
featureCompatibilityVersion
to"4.0"
.The
setFeatureCompatibilityVersion
command performs writes to an internal system collection and is idempotent. If for any reason the command does not complete successfully, retry the command on themongod
instance.
2. Remove FCV 4.2 Persisted Features¶
The following steps are necessary only if fCV has ever been set to
"4.2"
.
Remove all persisted 4.2 features that are incompatible with 4.0. These include:
2a. Index Key Size¶
Starting in MongoDB 4.2, for featureCompatibilityVersion
(fCV)
set to "4.2"
or greater, MongoDB removes the Index Key
Limit
. For fCV set to "4.0"
, the limit still applies.
If you have an index with keys that exceed the Index Key
Limit
once fCV is set to "4.0"
,
consider changing the index to a hashed index or to indexing a
computed value. You can also temporarily use
failIndexKeyTooLong
set to false
before resolving
the problem. However, with failIndexKeyTooLong
set to
false
, queries that use these indexes can return incomplete
results.
2b. Index Name Length¶
Starting in MongoDB 4.2, for featureCompatibilityVersion
(fCV)
set to "4.2"
or greater, MongoDB removes the Index Name
Length
. For fCV set to "4.0"
, the limit still applies.
If you have an index with a name that exceeds the Index Name
Length
once fCV is set to "4.0"
,
drop and recreate the index with a shorter name.
2c. Unique Index Version¶
With featureCompatibilityVersion
(fCV) "4.2"
, MongoDB uses a
new internal format for unique indexes that is incompatible with
MongoDB 4.0. The new internal format applies to both existing unique
indexes as well as newly created/rebuilt unique indexes.
If fCV has ever been set to "4.2"
, use the following script to
drop and recreate all unique indexes.
Tip
Perform this operation after you have resolved any index key size and index name length issues first.
- Script
2d. Remove Wildcard Indexes¶
For featureCompatibilityVersion
(fCV) set to "4.2"
, MongoDB
supports creating Wildcard Indexes. You must drop all
wildcard indexes before downgrading to fCV "4.0"
.
Use the following script to drop and recreate all wildcard indexes:
Important
Downgrading to fCV "4.0"
during an in-progress wildcard index
build does not automatically drop or kill the index build. The
index build can complete after downgrading to fcv "4.0"
,
resulting in a valid wildcard index on the collection. Starting
the 4.0 binary against against that data directory will result in
startup failures.
Use db.currentOp()
to check for any in-progress wildcard
index builds. Once any in-progress wildcard index builds complete,
run the script to drop them before downgrading to
fCV "4.0"
.
2e. View Definitions/Collection Validation Definitions that Include 4.2 Operators¶
Before downgrading the binaries, modify read-only view definitions and collection validation definitions
that include the 4.2 operators, such as
$set
, $unset
, $replaceWith
.
- For the
$set
stage, use the$addFields
stage instead. - For the
$replaceWith
stage, use the$replaceRoot
stage instead. - For the
$unset
stage, use the$project
stage instead.
You can modify a view either by:
- dropping the view (
db.myview.drop()
method) and recreating the view (db.createView()
method) or - using the
collMod
command.
You can modify the colleciton validation expressions by:
- using the
collMod
command.
3. Update tls
-Prefixed Configuration¶
Starting in MongoDB 4.2, MongoDB adds "tls"
-prefixed options as
aliases for the "ssl"-prefixed
options.
If your deployments or clients use the "tls"
-prefixed options,
replace with the corresponding "ssl"-prefixed
options for the
mongod, the mongos, and the mongo shell
and drivers.
4. Prepare Downgrade from zstd
Compression¶
zstd
Data Compression¶
The zstd compression library is available starting in version 4.2.
If your standalone has any data using zstd compression:
Tip
Perform this step after all the other prerequisite steps have been performed.
Stop all writes to your instance.
Create a
mongodump
of your database before starting the downgrade;mongodump
outputs uncompressed data.Include any other options, such as
--username
,--password
, and--authenticationDatabase
if your standalone enforces access control.Create a new empty
data directory
for themongod
instance. This directory will be used in the downgrade procedure below.Important
Ensure that the user account running
mongod
has read and write permissions for the new directory.If you use a configuration file, update the file to prepare for the downgrade procedure:
- Delete
storage.wiredTiger.collectionConfig.blockCompressor
to use the default compressor (snappy
) or set to another 4.0 supported compressor. - Update
storage.dbPath
to the new data directory.
If you use command-line options instead, you will have to update the options in the procedure below.- Delete
zstd
Journal Compression¶
The zstd compression library is available for journal data compression starting in version 4.2.
If the mongod
instance uses zstd library for
its journal compressor:
- If using a configuration file, delete
storage.wiredTiger.engineConfig.journalCompressor
to use the default compressor (snappy
) or set to another 4.0 supported compressor. - If using command-line options instead, you will have to update the options in the procedure below.
zstd
Network Compression¶
The zstd compression library is available for network message compression starting in version 4.2.
To prepare for the downgrade:
For the
mongod
instance that uses zstd for network message compression and uses a configuration file, update thenet.compression.compressors
setting to prepare for the restart during the downgrade procedure.If you use command-line options instead, you will have to update the options in the procedure below.For any client that specifies
zstd
in itsURI connection string
, update to removezstd
from the list.For any
mongo
shell that specifieszstd
in its--networkMessageCompressors
, update to removezstd
from the list.
Important
Messages are compressed when both parties enable network compression. Otherwise, messages between the parties are uncompressed.
5. Remove Client-Side Field Level Encryption Document Validation Keywords¶
Important
Remove client-side field level encryption code in applications prior to downgrading the server.
MongoDB 4.2 adds support for
enforcing client-side field level encryption as part of a collection’s
JSON Schema document validation. Specifically,
the $jsonSchema
object supports the
encrypt
and encryptMetadata
keywords. MongoDB 4.0 does not support these keywords and fails to
start if any collection specifies those keywords as part of its
validation $jsonSchema
.
Use db.getCollectionInfos()
on each database to identify
collections specifying automatic field level encryption rules as part of
the $jsonSchema
validator. To prepare for downgrade, do either
of the following operations for each
collection using the 4.0-incompatible keywords:
Use
collMod
to modify the collection’svalidator
and replace the$jsonSchema
with a schema that contains only 4.0-compatible document validation syntax:-or-
Procedure¶
Warning
Before proceeding with the downgrade procedure, ensure that the prerequisites have been completed.
Download the latest 4.0 binaries.¶
Using either a package manager or a manual download, get the latest release in the 4.0 series. If using a package manager, add a new repository for the 4.0 binaries, then perform the actual downgrade process.
Once upgraded to 4.2, if you need to downgrade, we recommend downgrading to the latest patch release of 4.0.
Restart with the latest 4.0 mongod
instance.¶
Shut down your
mongod
instance. To safely terminate themongod
process, you can connect amongo
shell to the instance and run:For additional methods to safely terminate your
mongod
instance, see Stop mongod Processes.Replace the 4.2 binary with the downloaded 4.0
mongod
binary and restart.Note
If you use command-line options instead of a configuration file, update the command-line options as appropriate during the restart.
- If your command-line options include “tls”-prefixed options, update to “ssl”-prefixed options.
- If the
mongod
instance usedzstd
data compression,- Update
--dbpath
to the new directory (created during the prerequisites). - Remove
--wiredTigerCollectionBlockCompressor
to use the defaultsnappy
compressor (or, alternatively, explicitly set to a 4.0 supported compressor).
- Update
- If the
mongod
instance usedzstd
journal compression,- Remove
--wiredTigerJournalCompressor
to use the defaultsnappy
compressor (or, alternatively, explicitly set to a 4.0 supported compressor).
- Remove
- If the
mongod
instance includedzstd
network message compression,- Remove
--networkMessageCompressors
to enable message compression using the defaultsnappy,zlib
compressors. Alternatively, explicitly specify the compressor(s).
- Remove
If switching from zstd
compression, restore data.¶
Skip this step if you have not downgraded from a standalone that used zstd compression.
If you have downgraded from a standalone that used zstd, you
have created a dump of your data as a prerequisite. Use mongorestore
to restore that data to your 4.0 standalone.