On this page本页内容
MongoDB versioning have the form MongoDB版本控制的格式为X.Y.Z
where Z
refers to the revision/patch number. X.Y.Z
,其中Z
表示版本号/补丁号。Revisions provide security patches, bug fixes, and new or changed features that generally do not contain any backward breaking changes. 修订版提供了安全补丁、错误修复,以及通常不包含任何向后破坏性更改的新功能或更改的功能。Always upgrade to the latest revision in your release series.始终升级到发行版系列中的最新版本。
For more information on versioning, see MongoDB Versioning.有关版本控制的更多信息,请参阅MongoDB版本控制。
Ensure you have an up-to-date backup of your data set. 确保数据集的备份是最新的。See MongoDB Backup Methods.请参阅MongoDB备份方法。
Consult the following documents for any special considerations or compatibility issues specific to your MongoDB release:有关MongoDB版本的任何特殊注意事项或兼容性问题,请参阅以下文档:
If your installation includes replica sets, plan the upgrade during a predefined maintenance window.如果您的安装包含副本集,请在预定义的维护窗口期间计划升级。
Starting in MongoDB 4.0.7, change streams use a version 1 从MongoDB 4.0.7开始,change streams使用v1
resume tokens. v1
的恢复令牌。MongoDB versions earlier than 4.0.7 use 4.0.7之前的MongoDB版本使用v0
resume tokens.v0
恢复令牌。
When upgrading from MongoDB 4.0.6 or earlier to MongoDB 4.0.7 or later, a client may try to resume change streams using the new 从MongoDB 4.0.6或更早版本升级到MongoDB 4.0.7或更高版本时,当连接到未更新的成员(即仅接受v1
resume token when connected to a member that has not been updated (i.e. only accepts v0
or BinData token) and fail. v0
或BinData令牌)并失败时,客户端可能会尝试使用新的v1
resume令牌恢复更改流。In such cases, the client must wait for the upgrade to complete before resuming change streams.在这种情况下,客户端必须等待升级完成,然后才能恢复更改流。
Before you upgrade a production environment, use the procedures in this document to upgrade a staging environment that reproduces your production environment, to ensure that your production configuration is compatible with all changes.升级生产环境之前,请使用本文档中的步骤升级复制生产环境的临时环境,以确保生产配置与所有更改兼容。
Upgrade each 使用此处描述的过程分别升级每个mongod
and mongos
binary separately, using the procedure described here. mongod
和mongos
二进制文件。When upgrading a binary, use the procedure Upgrade a MongoDB Instance.升级二进制文件时,请使用升级MongoDB实例的过程。
Follow this upgrade procedure:请遵循以下升级过程:
To upgrade a 要升级mongod
or mongos
instance, use one of these approaches:mongod
或mongos
实例,请使用以下方法之一:
This section describes how to upgrade MongoDB by replacing the existing binaries. 本节介绍如何通过替换现有二进制文件来升级MongoDB。The preferred approach to an upgrade is to use the operating system's package management tool and the official MongoDB packages, as described in Install MongoDB.升级的首选方法是使用操作系统的包管理工具和官方MongoDB包,如安装MongoDB中所述。
To upgrade a 要通过替换现有二进制文件升级mongod
or mongos
instance by replacing the existing binaries:mongod
或mongos
实例,请执行以下操作:
To upgrade a replica set, upgrade each member individually, starting with the secondaries and finishing with the primary. 要升级副本集,请分别升级每个成员,从secondaries开始,到primary结束。Plan the upgrade during a predefined maintenance window.在预定义的维护窗口期间计划升级。
Before you upgrade or downgrade a replica set, ensure all replica set members are running. 在升级或降级副本集之前,请确保所有副本集成员都在运行。If you do not, the upgrade or downgrade will not complete until all members are started.如果不这样做,升级或降级将在所有成员启动之前完成。
Starting in MongoDB 4.0.7, change streams use a version 1 从MongoDB 4.0.7开始,更改流使用v1
resume tokens. v1
的恢复令牌。MongoDB versions earlier than 4.0.7 use 4.0.7之前的MongoDB版本使用v0
resume tokens or BinData resume tokens.v0
恢复令牌或BinData恢复令牌。
When upgrading from MongoDB 4.0.0-4.0.6 to MongoDB 4.0.7 or later, a client may try to resume change streams using the new 从MongoDB 4.0.0-4.0.6升级到MongoDB 4.0.7或更高版本时,当连接到未更新的成员(即仅接受v0令牌或BinData)且失败时,客户端可能会尝试使用新的v1
resume token when connected to a member that has not been updated (i.e. only accepts v0
token or BinData) and fail. v1
恢复令牌恢复更改流。In such cases, the client must wait for the upgrade to complete before resuming change streams.在这种情况下,客户端必须等待升级完成,然后才能恢复更改流。
Upgrade each secondary separately as follows:按如下方式分别升级每个辅助设备:
mongod
binary by following the instructions in Upgrade a MongoDB Instance.mongod
二进制文件。After upgrading a secondary, wait for the secondary to recover to the 升级次实例后,请等待次实例恢复到SECONDARY
state before upgrading the next instance. SECONDARY
状态,然后再升级下一个实例。To check the member's state, issue 要检查成员的状态,请在rs.status()
in mongosh
.mongosh
中发出rs.status()
。
The secondary may briefly go into 第二阶段可能会短暂进入STARTUP2
or RECOVERING
. STARTUP2
或RECOVERING
阶段。This is normal. 这很正常。Make sure to wait for the secondary to fully recover to 在继续升级之前,请确保等待辅助服务器完全恢复到SECONDARY
before you continue the upgrade.SECONDARY
。
Step down the primary to initiate the normal failover procedure. 关闭主设备以启动正常的故障切换过程。Using one of the following:使用以下选项之一:
rs.stepDown()
helper in mongosh
.mongosh
的rs.stepDown()
助手。replSetStepDown
database command.replSetStepDown
数据库命令。During failover, the set cannot accept writes. 故障转移期间,该集无法接受写入。Typically this takes 10-20 seconds. 通常这需要10-20秒。Plan the upgrade during a predefined maintenance window.在预定义的维护窗口期间计划升级。
Stepping down the primary is preferable to directly shutting down the primary. 与直接关闭主电源相比,最好是关闭主电源。Stepping down expedites the failover procedure.退出将加快故障切换过程。
rs.status()
method from mongosh
until you see that another member has assumed the PRIMARY
state.mongosh
调用rs.status()
方法,直到看到另一个成员已采用PRIMARY
状态。Changed in version 3.4.在版本3.4中更改。
Starting in MongoDB 4.0.7, change streams use a version 1 从MongoDB 4.0.7开始,变更流使用版本1的恢复令牌。v1
resume tokens. MongoDB versions earlier than 4.0.7 use 4.0.7之前的MongoDB版本使用v0
resume tokens or BinData resume tokens.v0
恢复令牌或BinData恢复令牌。
When upgrading from MongoDB 4.0.6 or earlier to 4.0.7 or later, the members of the sharded clusters will continue to produce 当从MongoDB 4.0.6或更早版本升级到4.0.7或更高版本时,分片集群的成员将继续生成v0
or BinData resume tokens until the mongos
instance(s) are updated. v0
或BinData resume令牌,直到mongos
实例更新。Upgraded 升级后的mongos
instances will begin producing v1
change stream resume tokens. mongos
实例将开始生成v1变更流恢复令牌。These tokens cannot be used to resume a stream on a 这些令牌不能用于恢复mongos
that has not yet been upgraded to 4.0.7 or later.mongos
上尚未升级到4.0.7或更高版本的流。
To upgrade a 5.0 sharded cluster:要升级5.0分片群集,请执行以下操作:
Upgrade the config servers.升级配置服务器。
To upgrade the config server replica set, use the procedures in Upgrade Replica Sets.要升级配置服务器副本集,请使用升级副本集中的步骤。
Upgrade each shard.升级每个分片。
mongos
instance by following the instructions in Upgrade a MongoDB Instance. mongos
实例。mongos
instances in any order.mongos
实例。