定义
setFeatureCompatibilityVersionEnables or disables the features that persist data incompatible with earlier versions of MongoDB. You can only issue the
setFeatureCompatibilityVersionagainst theadmindatabase.
警告
启用向后不兼容的功能可能会使降级过程变得复杂,因为在降级之前,您必须删除任何持续存在的向后不兼容的功能。
升级后,允许部署在不启用向后不兼容功能的情况下运行一段稳定期。仅在确保不太可能降级后才启用这些功能。
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
在版本7.0中进行了更改。
该命令具有以下语法:
db.adminCommand( { setFeatureCompatibilityVersion: <version>, confirm: true, writeConcern: { wtimeout: <timeout> } } )
命令字段
setFeatureCompatibilityVersion 命令接受以下字段:
setFeatureCompatibilityVersion
必需
version 的可能值是:
版本 | 说明 |
|---|---|
| 可用于 MongoDB 8.0 部署 |
| 在 MongoDB 7.0 部署中可用 |
| 在 MongoDB 6.0 和 7.0 部署中可用 启用保留与MongoDB 5.0不兼容的数据的6.0功能。 |
| 在 MongoDB 5.0 和 6.0 部署中可用 启用保留与MongoDB 4.4不兼容的数据的5.0功能。 |
确认
必需
7.0版本新增。
设置为 true 以确认功能兼容性更改并允许操作继续。
If you omit the confirm parameter or set confirm to a value other than true, the command fails and returns a warning about modifying the feature compatibility version. The warning states that after you upgrade or downgrade your cluster's FCV, you cannot downgrade the binary version without support assistance.
writeConcern
Optional
writeConcern 以毫秒为单位指定写关注 wtimeout 值:
主节点等待大多数副本集成员确认的时间段。如果在该时间段内未收到确认,则操作失败。
行为
8如果必须将特征兼容性版本降级到.0 以下,则必须先运行transitionToDedicatedConfigServer 命令。有关降级的详细信息,请参阅降级功能兼容性版本。
使用前向不兼容数据进行升级
If you try to upgrade the FCV of a cluster that contains forwards-incompatible data in the upgraded version, you receive a CannotUpgrade error. Forwards-incompatible data can refer to any data in your cluster that relies on a feature that was removed in the target version.
出现此错误时,请执行以下任一操作:
Modify your cluster data to remove forwards-incompatible features, then re-run the
setFeatureCompatibilityVersioncommand with the upgraded version to set the FCV to the upgraded version.Run the
setFeatureCompatibilityVersioncommand with the original downgraded version to set the FCV back to the original version.重要
Setting the FCV to the original version stops the upgrade procedure and reverts the FCV to the downgraded version. The cluster does not return to its state before the FCV upgrade began.
If the FCV upgrade confirms that there is no forwards-incompatible data but otherwise stops or fails, any subsequent FCV downgrade attempts also fail with an error message. You must complete the FCV upgrade before you can downgrade the FCV.
使用向后不兼容的数据进行降级
If you try to downgrade the FCV of a cluster that contains incompatible data in the downloaded version, you receive a CannotDowngrade error. When this error occurs, the cluster remains in the transitionary downgrading state.
要将集群移出 downgrading 状态,请执行以下任一操作:
修改集群数据以删除向后兼容的功能,然后使用降级版本重新运行
setFeatureCompatibilityVersion命令,将 fCV 设置为降级版本。使用原始升级版本运行
setFeatureCompatibilityVersion命令,以便将 fCV 重新设置为原始版本。重要
Setting the FCV to the original version stops the downgrade procedure and reverts the FCV to the upgraded version. The cluster does not return to its state before the FCV downgrade began.
If the FCV downgrade confirms that there is no backwards-incompatible data but otherwise stops or fails, any subsequent FCV upgrade attempts also fail with an error message. You must complete the FCV downgrade before you can upgrade the FCV.
MongoDB 7.0 中的降级策略变更
从 MongoDB 7.0 开始,您无法将部署的 FCV 降级到 MongoDB 的快速发布版或从快速发布版降级。
如果您升级或降级部署的 fCV,没有支持人员的帮助,您无法降级部署的二进制版本。
要了解详情,请参阅《将 7.0 降级至 6.0》。
与后台操作冲突
Certain background operations may prevent execution of setFeatureCompatibilityVersion. Use currentOp to identify any ongoing operations.
同步失败
If you change the FCV during an initial sync, the sync may fail with an OplogOperationUnsupported error when replaying entries on the oplog application phase. The next sync succeeds because the operation phase no longer replays the operation.
Default Values
部署 | featureCompatibilityVersion |
|---|---|
对于新的 7.0 部署 |
|
从 6.0 升级的 7.0 部署 |
|
对于新的 6.0 部署 |
|
对于从 5.0 升级的 6.0 部署 |
|
幂等
此命令必须对内部系统集合执行写入操作。如果命令未能成功完成,则可安全地重试。该操作是幂等的。
Cluster-to-Cluster Sync 和用户写入阻塞
从 MongoDB 6.0 开始,如果需要降级特征兼容性版本,请确保禁用集群到集群复制和用户写入阻止。
如果您启用了集群到集群复制,请将其禁用。
如果启用了用户写入阻止,请将其禁用:
db.runCommand( { setUserWriteBlockMode: 1, global: false } ) 等待上一条命令完成。
Downgrade the feature compatibility version using
setFeatureCompatibilityVersion.
有关 MongoDB Cluster-to-Cluster Sync 的更多信息,请参阅文档。
仲裁节点中的功能兼容性
仲裁节点不会复制 admin.system.version 集合。因此,无论副本集的 fCV 值如何,仲裁节点始终具有等于二进制文件的降级版本的特征兼容性版本。
示例, MongoDB 5.0集群中的仲裁节点的FCV值为 4.4。
示例
获取 FeatureCompatibilityVersion
要查看 mongod 实例的 featureCompatibilityVersion,请在 mongod 实例上运行 getParameter 命令:
db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
输出类似如下所示:
{ featureCompatibilityVersion: { version: '5.0' }, ok: 1, '$clusterTime': { clusterTime: Timestamp({ t: 1660318752, i: 5 }), signature: { hash: Binary(Buffer.from("ce0cff3621e9b089fa6d8e9a1e1efc1a1ff15dab", "hex"), 0), keyId: Long("7129893797260951557") } }, operationTime: Timestamp({ t: 1660318752, i: 5 }) }
在 MongoDB 7.0 部署上设置功能兼容性版本
启用 7.0 向后不兼容的功能
要启用保留与 MongoDB 6.0 不兼容的数据的 7.0 功能,请在 MongoDB 7.0 部署上将功能兼容性设置为"7.0":
注意
Run the setFeatureCompatibilityVersion command against the admin database.
db.adminCommand( { setFeatureCompatibilityVersion: "7.0", confirm: true } )
禁用 7.0 向后不兼容的功能
要禁用保留与 MongoDB 6.0 不兼容的数据的 7.0 功能,请在 MongoDB 7.0 部署上将功能兼容性设置为"6.0":
注意
Run the setFeatureCompatibilityVersion command against the admin database.
"6.0"仅 MongoDB 6.0 和 MongoDB 7.0 部署支持 featureCompatibilityVersion。
db.adminCommand( { setFeatureCompatibilityVersion: "6.0", confirm: true } )
如果作为从 MongoDB 7.0 降级到 MongoDB 6.0 的过程的一部分运行,则还必须删除所有与 6.0 不兼容的保留功能。请参阅相应的降级程序。
为 MongoDB 6.0 部署设置特征兼容性版本
启用 6.0 向后不兼容的功能
要启用保留与MongoDB 5.0 不兼容的数据的 6.0 功能,请在MongoDB 6.0部署上将功能兼容性设立为 "6.0":
注意
Run the setFeatureCompatibilityVersion command against the admin database.
db.adminCommand( { setFeatureCompatibilityVersion: "6.0" } )
禁用 7.0 向后不兼容的功能
要禁用保留与MongoDB 5.0 不兼容的数据的 6.0 功能,请在MongoDB 6.0部署上将功能兼容性设立为 "5.0":
注意
Run the setFeatureCompatibilityVersion command against the admin database.
"5.0"仅 MongoDB 5.0 和 MongoDB 6.0 部署支持 featureCompatibilityVersion。
db.adminCommand( { setFeatureCompatibilityVersion: "5.0" } )
如果作为从MongoDB 6.0 降级到MongoDB 5.0 的进程的一部分运行,则还必须删除与 5.0 不兼容的所有保留功能。请参阅相应的降级程序。
设置写关注超时
以下示例将可选写关注 wtimeout 字段设置为 5000(5 秒)。
注意
Run the setFeatureCompatibilityVersion command against the admin database.
db.adminCommand( { setFeatureCompatibilityVersion: "5.0", writeConcern: { wtimeout: 5000 } } )
故障排除
If you experience startup issues after setting your feature compatibility version, contact MongoDB Support for assistance.