On this page本页内容
Before you attempt any downgrade, familiarize yourself with the content of this document.
Once upgraded to 4.4, if you need to downgrade, we recommend downgrading to the latest patch release of 4.2.
Downgrade Floor
If you need to downgrade form version 4.4, downgrade to 4.2.6 or a later version. You cannot downgrade to 4.2.5 or an earlier version.
Optional but Recommended. Create a backup of your database.
To downgrade from 4.4 to 4.2, you must remove incompatible features that are persisted and/or update incompatible configuration settings.
Starting in MongoDB 4.4:
"4.4"
or greater, MongoDB raises the limit on collection/view namespace to 255 bytes. For a collection or a view, the namespace includes the database name, the dot (.
) separator, and the collection/view name (e.g. <database>.<collection>
),"4.2"
or earlier, the maximum length of the collection/view namespace remains 120 bytes.Before downgrading, resolve any collections or views with namespaces that exceed the 120-byte Namespace Length
limit for Feature Compatibility Version (fCV) 4.2.
To determine if you have any collections or views with namespaces that exceed the 120-byte limit, connect mongo
shell to a mongos
instance and run:
If any collection or view namespace exceeds 120 bytes, then prior to downgrading the fCV:
renameCollection
command.$merge
to a new sharded collection with a shorter name, then drop the original collection.mongoexport
and mongoimport
into a new collection with a shorter name, then drop the original collection.db.createView()
to recreate the view using a shorter name, then drop the original view.Tip
replSetReconfig
on each shard to remove the term
field from the configuration document and blocks until the new configuration propagates to a majority of replica set members.To downgrade the featureCompatibilityVersion
of your sharded cluster:
mongo
shell to the mongos
instance.featureCompatibilityVersion
to "4.2"
.
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 the mongos
instance.
Note
While setFeatureCompatibilityVersion
is running on the sharded cluster, chunk migrations, splits, and merges can fail with ConflictingOperationInProgress
.
featureCompatibilityVersion
, 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.
All members should return a result that includes:
If any member returns a featureCompatibilityVersion
of "4.4"
, wait for the member to reflect version "4.2"
before proceeding.
For more information on the returned featureCompatibilityVersion
value, see View FeatureCompatibilityVersion.
The following steps are necessary only if fCV has ever been set to "4.4"
.
Remove all persisted 4.4 features that are incompatible with 4.2. These include:
Remove all compound hashed indexes.
Use db.collection.getIndexes()
to identify any compound hashed indexes in a collection and use db.collection.dropIndex()
to remove those indexes.
If any collection is sharded using the compound hashed index, use the guidance listed under Compound Hashed Shard Keys
below.
Remove any sharded collections which were sharded using a compound hashed shard key.
Use sh.status()
to identify sharded collections with a compound hashed shard key and remove those collections.
db.collection.drop()
to drop the collection.db.collection.drop()
to drop the collection. After downgrading the cluster, restore the data into the cluster.Remove all persisted features that use 4.4 features. These include but are not limited to:
$unionWith
or $function
. See also New Aggregation Operators.Unhide
or drop
hidden indexes.In MongoDB 4.4, shard key fields can be missing from documents in a sharded collection.
If you downgrade to 4.2 and a sharded collection contains documents missing shard key fields, 4.2 mongos
instances do not return documents that are missing the shard key fields. To avoid this situation, update the documents to includes the missing shard key fields before you downgrade.
To find documents that are missing any part of the shard key, use the $exists
operator.
For example, if the collection contacts
has the shard key {
zipcode: 1 }
, to find documents without the zipcode
field:
To set the missing shard key field to null
for these documents, you can use the db.collection.updateMany()
method:
If setting the missing shard key field to a non-null
value, you cannot use the db.collection.updateMany()
method and you must perform the update within a transaction or as a retryable write. For details, see Set the Missing Shard Key Fields.
Warning
Before proceeding with the downgrade procedure, ensure that all members, including delayed replica set members in the sharded cluster, reflect the prerequisite changes. That is, check the featureCompatibilityVersion
and the removal of incompatible features for each node before downgrading.
Using either a package manager or a manual download, get the latest release in the 4.2 series. If using a package manager, add a new repository for the 4.2 binaries, then perform the actual downgrade process.
Once upgraded to 4.4, if you need to downgrade, we recommend downgrading to the latest patch release of 4.2.
Connect a mongo
shell to a mongos
instance in the sharded cluster, and run sh.stopBalancer()
to disable the balancer:
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:
For more information on disabling the balancer, see Disable the Balancer.
mongos
instances.¶Downgrade the binaries and restart.
Downgrade the shards one at a time.
mongod
instance.
SECONDARY
state before downgrading the next secondary member. To check the member’s state, connect a mongo
shell to the shard and run rs.status()
method.
Repeat to downgrade for each secondary member.
Skip this step if the replica set does not include an arbiter.
mongod
. See Stop mongod Processes for additional ways to safely terminate mongod
processes.
storage.dbPath
configuration setting or --dbpath
command line option specify the data directory of the arbiter mongod
.
ARBITER
state. To check the member’s state, connect a mongo
shell to the member and run rs.status()
method.mongo
shell to the primary and use rs.stepDown()
to step down the primary and force an election of a new primary:
rs.status()
.
When the status shows that the primary has stepped down and another member has assumed PRIMARY
state, proceed.
Repeat for the remaining shards.
mongod
instance.
SECONDARY
state before downgrading the next secondary member. To check the member’s state, connect a mongo
shell to the shard and run rs.status()
method.
Repeat to downgrade for each secondary member.
mongo
shell to the primary and use rs.stepDown()
to step down the primary and force an election of a new primary:
rs.status()
.
When the status shows that the primary has stepped down and another member has assumed PRIMARY
state, proceed.
Once the downgrade of sharded cluster components is complete, connect a mongo
shell to a mongos
and re-enable the balancer.
The mongo
shell method sh.startBalancer()
also enables auto-splitting for the sharded cluster.