On this page本页内容
Before you attempt any downgrade, familiarize yourself with the content of this document, particularly the Downgrade Recommendations and Checklist and the procedure for downgrading sharded clusters.
When downgrading, consider the following:
Once upgraded to MongoDB 2.6, you cannot downgrade to any version earlier than MongoDB 2.4. If you created text
or 2dsphere
indexes while running 2.6, you can only downgrade to MongoDB 2.4.10 or later.
Follow the downgrade procedures:
If you have upgraded to the 2.6 user authorization model, you must first downgrade the user authorization model to 2.4 before before downgrading MongoDB 2.6 to 2.4.
admin.system.backup_users
and admin.system.new_users
collections created during the upgrade process.To downgrade the authorization model, you must connect as a user with the following privileges:
If no user exists with the appropriate privileges, create an authorization model downgrade user:
Connect and authenticate as a user with userAdminAnyDatabase
.
Using the db.createRole
method, create a role with the required privileges.
Create a user and assign the user the downgradeRole
.
Note
Instead of creating a new user, you can also grant the role to an existing user. See db.grantRolesToUser()
method.
Authenticate as the newly created user.
The method returns 1
upon successful authentication.
The following downgrade procedure requires <database>.system.users
collections used in version 2.4. to be intact for non-admin
databases.
Connect and authenticate to the mongod
instance for a single deployment or a mongos
for a sharded cluster with the appropriate privileges. See Access Control Prerequisites for details.
admin.system.users
collection.¶Copy all documents in the admin.system.users
collection to the admin.system.new_users
collection:
authSchema
.¶The method returns a WriteResult
object with the status of the operation. Upon successful update, the WriteResult
object should have "nModified"
equal to 1
.
admin.system.users
collection.¶The method returns a WriteResult
object with the number of documents removed in the "nRemoved"
field.
admin.system.backup_users
collection.¶Copy all documents from the admin.system.backup_users
, created during the 2.6 upgrade, to admin.system.users
.
authSchema
.¶For a sharded cluster, repeat the downgrade process by connecting to the primary replica set member for each shard.
Note
The cluster’s mongos
instances will fail to detect the authorization model downgrade until the user cache is refreshed. You can run invalidateUserCache
on each mongos
instance to refresh immediately, or you can wait until the cache is refreshed automatically at the end of the user cache invalidation interval
. To run invalidateUserCache
, you must have privilege with invalidateUserCache
action, which is granted by userAdminAnyDatabase
and hostManager
roles.
The downgrade process returns the user data to its state prior to upgrading to 2.6 authorization model. Any changes made to the user/role data using the 2.6 users model will be lost.
If you have version 2 text indexes (i.e. the default version for text indexes in MongoDB 2.6), drop the version 2 text indexes before downgrading MongoDB. After the downgrade, enable text search and recreate the dropped text indexes.
To determine the version of your text
indexes, run db.collection.getIndexes()
to view index specifications. For text indexes, the method returns the version information in the field textIndexVersion
. For example, the following shows that the text
index on the quotes
collection is version 2.
2dsphere
Index Version Check¶If you have version 2 2dsphere
indexes (i.e. the default version for 2dsphere
indexes in MongoDB 2.6), drop the version 2
2dsphere
indexes before downgrading MongoDB. After the downgrade, recreate the 2dsphere
indexes.
To determine the version of your 2dsphere
indexes, run db.collection.getIndexes()
to view index specifications. For 2dsphere
indexes, the method returns the version information in the field 2dsphereIndexVersion
. For example, the following shows that the 2dsphere
index on the locations
collection is version 2.
mongod
Instance¶The following steps outline the procedure to downgrade a standalone mongod
from version 2.6 to 2.4.
mongod
instance. Replace the existing binary with the 2.4 mongod
binary and restart mongod
.The following steps outline a “rolling” downgrade process for the replica set. The “rolling” downgrade process minimizes downtime by downgrading the members individually while the other members are available:
For each secondary in a replica set:
mongod
instances.¶First, shut down the mongod
, then replace these binaries with the 2.4 binary and restart mongod
. See Stop mongod Processes for instructions on safely terminating mongod
processes.
Wait for the member to recover to SECONDARY
state before upgrading the next secondary.
To check the member’s state, use the rs.status()
method in the mongo
shell.
Use rs.stepDown()
in the mongo
shell to step down the primary and force the normal failover procedure.
rs.stepDown()
expedites the failover procedure and ismongod
.¶When rs.status()
shows that the primary has stepped down and another member has assumed PRIMARY
state, shut down the previous primary and replace the mongod
binary with the 2.4 binary and start the new instance.
Replica set failover is not instant but will render the set unavailable to writes and interrupt reads until the failover process completes. Typically this takes 10 seconds or more. You may wish to plan the downgrade during a predetermined maintenance window.
While the downgrade is in progress, you cannot make changes to the collection meta-data. For example, during the downgrade, do not do any of the following:
sh.enableSharding()
sh.shardCollection()
sh.addShard()
db.createCollection()
db.collection.drop()
db.dropDatabase()
The downgrade procedure for a sharded cluster reverses the order of the upgrade procedure.
mongod
secondaries before downgrading the primary.replSetStepDown
and downgrade.mongod
config server instances, leaving the first system in the mongos --configdb
argument to downgrade last.mongos
, one at a time. The downgrade process is a binary drop-in replacement.Once upgraded to MongoDB 2.6, you cannot downgrade to any version earlier than MongoDB 2.4. If you have text
or 2dsphere
indexes, you can only downgrade to MongoDB 2.4.10 or later.
Except as described on this page, moving between 2.4 and 2.6 is a drop-in replacement:
mongod
instance.¶For example, on Linux, run 2.6 mongod
with the --shutdown
option as follows:
Replace /var/mongod/data
with your MongoDB dbPath
. See also the Stop mongod Processes for alternate methods of stopping a mongod
instance.