定义
setFeatureCompatibilityVersion启用或禁用将与早期版本 MongoDB 不兼容的数据持久化的功能。您只能对
admin数据库发出setFeatureCompatibilityVersion。
警告
启用向后不兼容的功能可能会使降级过程变得复杂,因为在降级之前,您必须删除任何持续存在的向后不兼容的功能。
升级后,建议让部署在不启用向后不兼容功能的情况下稳定运行一段时间,以确保降级回老版本的可能性极小。当确信降级的可能性非常小时,请启用这些功能。
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
在版本8.3中进行了更改。
该命令具有以下语法:
db.adminCommand( { setFeatureCompatibilityVersion: <version>, confirm: true, writeConcern: { wtimeout: <timeout> }, dryRun: <boolean> } )
命令字段
setFeatureCompatibilityVersion 命令接受以下字段:
setFeatureCompatibilityVersion
必需
version 的可能值是:
版本 | 说明 |
|---|---|
| 可用于 MongoDB 8.3 部署 |
| 可用于MongoDB 8.2 和MongoDB 8.3部署 Starting in MongoDB 8.3, you can downgrade FCV from |
| 可用于 MongoDB 8.0 部署 |
| 在 MongoDB 7.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.
writeConcern
Optional
writeConcern 以毫秒为单位指定写关注 wtimeout 值:
干运行
Optional
If set to true, MongoDB simulates an upgrade or downgrade of the feature compatibility version. If the cluster contains incompatible data, the operation fails with an error.
8.3版本新增。
行为
如果必须将功能兼容性版本降级到 8.0 以下,则必须先运行 transitionToDedicatedConfigServer 命令。有关降级的详细信息,请参阅功能兼容性版本。
Upgrade with Forward-Incompatible Data
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.
When this error occurs, either:
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 changes the FCV back to the downgraded version. This procedure does not reset the cluster back to the 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 will also fail with an error message. You must complete the FCV upgrade before trying to downgrade the FCV.
使用向后不兼容的数据进行降级
If you try to downgrade the FCV of a cluster that contains backwards-incompatible data in the downgraded version, you receive a CannotDowngrade error. Backwards-incompatible data can refer to any data in your cluster that relies on a feature that isn't available in the target version.
When this error occurs, either:
修改集群数据以删除向后兼容的功能,然后使用降级版本重新运行
setFeatureCompatibilityVersion命令,将 fCV 设置为降级版本。使用原始升级版本运行
setFeatureCompatibilityVersion命令,以便将 fCV 重新设置为原始版本。重要
将 FcV 设置为原始版本会停止降级过程,并将 FcV 更改回升级版本。此过程不会将集群重置回到 FcV 降级开始之前的状态。
If the FCV downgrade confirms that there is no backwards-incompatible data but otherwise stops or fails, any subsequent FCV upgrade attempts will also fail with an error message. You must complete the FCV downgrade before trying to upgrade the FCV.
Downgrade Policy in MongoDB 8.3
Starting in 8.3, you can downgrade your deployment's FCV to the immediately previous minor version.
要学习;了解更多信息,请参阅将8.3降级至8.2 。
与后台操作冲突
某些后台操作可能会阻止 setFeatureCompatibilityVersion 的执行。使用 currentOp 确定任何正在进行的操作。
同步失败
如果在初始同步过程中触发 setFeatureCompatibilityVersion 更改,在 oplog 应用阶段重放条目时,同步可能会失败,并显示 OplogOperationUnsupported 错误信息。此尝试之后的同步会成功,因为操作阶段不再重放该操作。
Default Values
部署 | featureCompatibilityVersion |
|---|---|
对于新的8.3 部署 |
|
For 8.3 deployments upgraded from 8.2 |
|
对于新的8.0 部署 |
|
For 8.0 deployments upgraded from 7.0 |
|
对于新的 7.0 部署 |
|
从 6.0 升级的 7.0 部署 |
|
幂等
此命令执行的必须是对内部系统集合的写入。如果由于任何原因该命令未能成功完成,您都可以安全地重试该命令,因为该操作是幂等的。
Cluster-to-Cluster Sync 和用户写入阻塞
从 MongoDB 6.0 开始,如果需要降级特征兼容性版本,请确保禁用集群到集群复制和用户写入阻止。
如果您启用了集群到集群复制,请将其禁用。
如果启用了用户写入阻止,请将其禁用:
db.runCommand( { setUserWriteBlockMode: 1, global: false } ) 等待上一条命令完成。
使用
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 }) }
Set Feature Compatibility Version on MongoDB 8.0 Deployments
Enable 8.0 Backwards Incompatible Features
To enable the 8.0 features that persist data incompatible with MongoDB 7.0, set the feature compatibility to "8.0" on the MongoDB 8.0 deployment:
注意
对 admin 数据库运行 setFeatureCompatibilityVersion 命令。
db.adminCommand( { setFeatureCompatibilityVersion: "8.0", confirm: true } )
Disable 8.0 Backwards Incompatible Features
To disable the 8.0 features that persist data incompatible with MongoDB 7.0, set the feature compatibility to "7.0" on the MongoDB 8.0 deployment:
注意
对 admin 数据库运行 setFeatureCompatibilityVersion 命令。
"7.0"featureCompatibilityVersion is supported on MongoDB 7.0 and MongoDB 8.0 deployments.
db.adminCommand( { setFeatureCompatibilityVersion: "7.0", confirm: true } )
If you run this command as part of the downgrade process from MongoDB 8.0 to MongoDB 7.0, you must also remove all persisted features that are incompatible with 7.0. See the appropriate downgrade procedures.
在 MongoDB 7.0 部署上设置功能兼容性版本
启用 7.0 向后不兼容的功能
要启用保留与 MongoDB 6.0 不兼容的数据的 7.0 功能,请在 MongoDB 7.0 部署上将功能兼容性设置为"7.0":
注意
对 admin 数据库运行 setFeatureCompatibilityVersion 命令。
db.adminCommand( { setFeatureCompatibilityVersion: "7.0", confirm: true } )
禁用 7.0 向后不兼容的功能
要禁用保留与 MongoDB 6.0 不兼容的数据的 7.0 功能,请在 MongoDB 7.0 部署上将功能兼容性设置为"6.0":
注意
对 admin 数据库运行 setFeatureCompatibilityVersion 命令。
"6.0"仅 MongoDB 6.0 和 MongoDB 7.0 部署支持 featureCompatibilityVersion。
db.adminCommand( { setFeatureCompatibilityVersion: "6.0", confirm: true } )
如果作为从 MongoDB 7.0 降级到 MongoDB 6.0 的过程的一部分运行,则还必须删除所有与 6.0 不兼容的保留功能。请参阅相应的降级程序。
设置写关注超时
以下示例将可选写关注 wtimeout 字段设置为 5000(5 秒)。
注意
对 admin 数据库运行 setFeatureCompatibilityVersion 命令。
db.adminCommand( { setFeatureCompatibilityVersion: "5.0", writeConcern: { wtimeout: 5000 } } )