Definition定义
setFeatureCompatibilityVersionEnables or disables the features that persist data incompatible with earlier versions of MongoDB. You can only issue the启用或禁用与早期版本的MongoDB不兼容的持久化数据的功能。您只能对setFeatureCompatibilityVersionagainst theadmindatabase.admin数据库发出setFeatureCompatibilityVersion。
Warning
Enabling backwards-incompatible features can complicate the downgrade process since you must remove any persisted backwards-incompatible features before you downgrade.启用向后不兼容的功能可能会使降级过程复杂化,因为在降级之前必须删除任何持久的向后不兼容功能。
It is recommended that after upgrading, you allow your deployment to run without enabling backwards-incompatible features for a burn-in period to ensure the likelihood of downgrade is minimal. When you are confident that the likelihood of downgrade is minimal, enable these features.建议升级后,在老化期内允许部署运行,而不启用向后不兼容的功能,以确保降级的可能性最小。当您确信降级的可能性很小时,启用这些功能。
Compatibility兼容性
This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Syntax语法
Changed in version 7.0.在版本7.0中的更改。
The command has the following syntax:该命令具有以下语法:
db.adminCommand(
{
setFeatureCompatibilityVersion: <version>,
confirm: true,
writeConcern: { wtimeout: <timeout> }
}
)Command Fields命令字段
The setFeatureCompatibilityVersion command takes the following fields:setFeatureCompatibilityVersion命令包含以下字段:
setFeatureCompatibilityVersion
Required
The possible values for version are:version的可能值为:
"8.0" |
|
"7.0" |
|
"6.0" |
|
"5.0" |
|
confirm确认
Required必需的
New in version 7.0.在版本7.0中新增。
Set to 设置为true to confirm the feature compatibility change and allow the operation to proceed.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. confirm参数或将confirm设置为true以外的值,则该命令将失败,并返回有关修改功能兼容性版本的警告。The warning states that after you upgrade or downgrade your cluster's FCV, you cannot downgrade the binary version without support assistance.警告指出,升级或降级集群的FCV后,如果没有支持帮助,您将无法降级二进制版本。
writeConcern
Optional可选
The writeConcern specifies the write concern wtimeout value in milliseconds:writeConcern指定写入关注wtimeout值(以毫秒为单位):
The time period that the primary waits for acknowledgment from the majority of the replica set members. If the acknowledgment is not received in the time period, the operation fails.primary等待大多数副本集成员确认的时间段。如果在该时间段内未收到确认,则操作失败。Default is默认值为60000milliseconds.60000毫秒。Use a longer time period if the secondary members of the replica set have a delay that exceeds the如果副本集的secondary成员的延迟超过wtimeoutdefault.wtimeout默认值,请使用更长的时间段。
Note
For a standalone, run the command on the standalone对于单机版,在单机版mongodinstance.mongod实例上运行该命令。For a replica set, run the command on the primary. A majority of the data-bearing members must be available.对于副本集,在主服务器上运行该命令。大多数数据承载成员必须可用。For a sharded cluster, run the command on a对于分片集群,在mongosinstance.mongos实例上运行该命令。
Behavior行为
If you must downgrade the feature compatibility version below 8.0, you must first run the 如果必须将功能兼容性版本降级到8.0以下,则必须首先运行transitionToDedicatedConfigServer command. For downgrade details, see Downgrade Feature Compatibility Version.transitionToDedicatedConfigServer命令。有关降级的详细信息,请参阅降级功能兼容性版本。
Downgrade with Backward-Incompatible Data因数据向后不兼容而降级
If you try to downgrade the FCV of a cluster that contains incompatible data in the downloaded version, you receive a 如果您尝试降级下载版本中包含不兼容数据的集群的FCV,您将收到CannotDowngrade error. When this error occurs, the cluster remains in the transitionary downgrading state.CannotDowngrade错误。当发生此错误时,集群仍处于过渡降级状态。
To move the cluster out of the 要将集群移出downgrading state, either:downgrading(降级)状态,请执行以下操作之一:
Modify your cluster data to remove backwards-incompatible features, then re-run the修改集群数据以删除向后不兼容的功能,然后使用降级版本重新运行setFeatureCompatibilityVersioncommand with the downgraded version to set the FCV to the downgraded version.setFeatureCompatibilityVersion命令,将FCV设置为降级版本。Run the使用原始升级版本运行setFeatureCompatibilityVersioncommand with the original upgraded version to set the FCV back to the original version.setFeatureCompatibilityVersion命令,将FCV设置回原始版本。Important
Setting the FCV to the original version stops the downgrade procedure and changes the FCV back to the upgraded version. This procedure does not reset the cluster back to the state before the FCV downgrade began.将FCV设置为原始版本会停止降级过程,并将FCV更改回升级版本。此过程不会将群集重置回FCV降级开始前的状态。If a failed FCV downgrade's internal metadata is not cleaned up, any subsequent FCV upgrade attempt fails with an error message. You must complete the FCV downgrade before trying to upgrade the FCV.如果失败的FCV降级的内部元数据未被清理,则任何后续的FCV升级尝试都会失败,并显示错误消息。在尝试升级FCV之前,您必须完成FCV降级。
Downgrade Policy Changes in MongoDB 7.0MongoDB 7.0中的降级策略更改
Starting in MongoDB 7.0, you cannot downgrade your deployment's FCV to or from a minor release version of MongoDB.从MongoDB 7.0开始,您不能将部署的FCV降级到MongoDB的次要版本或从MongoDB的次要发布版本降级。
If you upgrade or downgrade your deployment's FCV, you cannot downgrade your deployment's binary version without assistance from support.如果升级或降级部署的FCV,则在没有支持人员帮助的情况下,无法降级部署的二进制版本。
To learn more, see Downgrade 7.0 to 6.0.要了解更多信息,请参阅降级7.0到6.0。
Conflicts with Background Operations与后台操作冲突
Certain background operations may prevent execution of 某些后台操作可能会阻止执行setFeatureCompatibilityVersion. Use currentOp to identify any ongoing operations.setFeatureCompatibilityVersion。使用currentOp识别任何正在进行的操作。
Sync Failures同步失败
If you trigger a 如果在初始同步期间触发setFeatureCompatibilityVersion change during an initial sync, the sync may fail with an OplogOperationUnsupported error message when replaying entries on the oplog application phase. setFeatureCompatibilityVersion更改,则在oplog应用程序阶段重放条目时,同步可能会失败,并显示OplogOperationUnsupported错误消息。The sync following this attempt succeeds because the operation phase no longer replays the operation.此尝试后的同步成功,因为操作阶段不再重放操作。
Default Values默认值
featureCompatibilityVersion | |
|---|---|
"7.0" | |
"6.0" until you setFeatureCompatibilityVersion to "7.0". | |
"6.0" | |
"5.0" until you setFeatureCompatibilityVersion to "6.0". |
Idempotency幂等性
This command must perform writes to an internal system collection. If for any reason the command does not complete successfully, you can safely retry the command as the operation is idempotent.此命令必须对内部系统集合执行写入操作。如果由于任何原因命令未成功完成,您可以安全地重试该命令,因为该操作是幂等的。
Cluster-to-Cluster Sync and User Write Blocking群集到群集同步和用户写入阻止
Starting in MongoDB 6.0, if you need to downgrade the feature compatibility version, ensure you disable cluster-to-cluster replication and user write blocking.从MongoDB 6.0开始,如果需要降级功能兼容性版本,请确保禁用集群到集群的复制和用户写阻塞。
If you enabled cluster-to-cluster replication, disable it.如果启用了群集到群集复制,请禁用它。If you enabled user write blocking, disable it:如果启用了用户写阻止,请禁用它:db.runCommand( { setUserWriteBlockMode: 1, global: false } )Wait for the previous command to complete.等待上一个命令完成。Downgrade the feature compatibility version using使用setFeatureCompatibilityVersion.setFeatureCompatibilityVersion降级功能兼容性版本。
For more information on MongoDB Cluster-to-Cluster Sync, see the documentation.有关MongoDB集群到集群同步的更多信息,请参阅文档。
Feature Compatibility in ArbitersArbiters中的功能兼容性
Arbiters do not replicate the 仲裁器不会复制admin.system.version collection. Because of this, arbiters always have a feature compatibility version equal to the downgrade version of the binary, regardless of the FCV value of the replica set.admin.system.version集合。因此,无论副本集的FCV值如何,仲裁器的功能兼容性版本始终等于二进制文件的降级版本。
For example, an arbiter in a MongoDB 5.0 cluster, has an FCV value of 4.4.例如,MongoDB 5.0集群中的仲裁器的FCV值为4.4。
Examples示例
Get 获取FeatureCompatibilityVersion
To view the 要查看mongd实例的featureCompatibilityVersion for a mongod instance, run the getParameter command on a mongod instance:featureCompatibilityVersion,请在mongod实例上运行getParameter命令:
db.adminCommand(
{
getParameter: 1,
featureCompatibilityVersion: 1
}
)
The output resembles:输出类似于:
{
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 })
}
Note
The operation is undefined on the mongos instances.mongos实例上的操作未定义。
On a sharded cluster that has access control enabled, you must connect to the shard as a shard local user to run the command.在启用了访问控制的分片集群上,您必须以分片本地用户的身份连接到分片才能运行命令。
Set Feature Compatibility Version on MongoDB 7.0 Deployments在MongoDB 7.0部署上设置功能兼容版本
Enable 7.0 Backwards Incompatible Features启用7.0向后不兼容功能
To enable the 7.0 features that persist data incompatible with MongoDB 6.0, set the feature compatibility to 要启用与MongoDB 6.0不兼容的持久化数据的7.0功能,请在MongoDB 7.0部署上将功能兼容性设置为“7.0”:"7.0" on the MongoDB 7.0 deployment:
Note
Run the 对setFeatureCompatibilityVersion command against the admin database.admin数据库运行setFeatureCompatibilityVersion命令。
For a standalone, run the command on the standalone对于单机版,在单机版mongodinstance.mongod实例上运行该命令。For a replica set, run the command on the primary. A majority of the data-bearing members must be available.对于副本集,在主服务器上运行该命令。大多数数据承载成员必须可用。For a sharded cluster, run the command on a对于分片集群,在mongosinstance.mongos实例上运行该命令。
db.adminCommand(
{
setFeatureCompatibilityVersion: "7.0",
confirm: true
}
)Disable 7.0 Backwards Incompatible Features禁用7.0向后不兼容功能
To disable the 7.0 features that persist data incompatible with MongoDB 6.0, set the feature compatibility to 要禁用与MongoDB 6.0不兼容的持久化数据的7.0功能,请在MongoDB 7.0部署上将功能兼容性设置为"6.0" on the MongoDB 7.0 deployment:"6.0":
Note
Run the 对setFeatureCompatibilityVersion command against the admin database.admin数据库运行setFeatureCompatibilityVersion命令。
For a standalone, run the command on the standalone对于单机版,在单机版mongodinstance.mongod实例上运行该命令。For a replica set, run the command on the primary. A majority of the data-bearing members must be available.对于副本集,在主服务器上运行该命令。大多数数据承载成员必须可用。For a sharded cluster, run the command on a对于分片集群,在mongosinstance.mongos实例上运行该命令。
“6.0”功能兼容性版本仅在MongoDB 6.0和MongoDB 7.0部署上受支持。"6.0"featureCompatibilityVersion is supported on MongoDB 6.0 and MongoDB 7.0 deployments only.
db.adminCommand(
{
setFeatureCompatibilityVersion: "6.0",
confirm: true
}
)
If run as part of the downgrade process from MongoDB 7.0 to MongoDB 6.0, you must also remove all persisted features that are incompatible with 6.0. See the appropriate downgrade procedures.如果作为从MongoDB 7.0到MongoDB 6.0的降级过程的一部分运行,您还必须删除与6.0不兼容的所有持久功能。请参阅相应的降级程序。
Set Feature Compatibility Version on MongoDB 6.0 Deployments在MongoDB 6.0部署上设置功能兼容版本
Enable 6.0 Backwards Incompatible Features启用6.0向后不兼容功能
To enable the 6.0 features that persist data incompatible with MongoDB 5.0 , set the feature compatibility to 要启用与MongoDB 5.0不兼容的持久化数据的6.0功能,请在MongoDB 6.0部署上将功能兼容性设置为“6.0”:"6.0" on the MongoDB 6.0 deployment:
Note
Run the 对setFeatureCompatibilityVersion command against the admin database.admin数据库运行setFeatureCompatibilityVersion命令。
For a standalone, run the command on the standalone对于单机版,在单机版mongodinstance.mongod实例上运行该命令。For a replica set, run the command on the primary. A majority of the data-bearing members must be available.对于副本集,在主服务器上运行该命令。大多数数据承载成员必须可用。For a sharded cluster, run the command on a对于分片集群,在mongosinstance.mongos实例上运行该命令。
db.adminCommand( { setFeatureCompatibilityVersion: "6.0" } )Disable 6.0 Backwards Incompatible Features禁用6.0向后不兼容功能
To disable the 6.0 features that persist data incompatible with MongoDB 5.0, set the feature compatibility to 要禁用与MongoDB 5.0不兼容的持久化数据的6.0功能,请在MongoDB 6.0部署上将功能兼容性设置为"5.0" on the MongoDB 6.0 deployment:"5.0":
Note
Run the 对setFeatureCompatibilityVersion command against the admin database.admin数据库运行setFeatureCompatibilityVersion命令。
For a standalone, run the command on the standalone对于单机版,在单机版mongodinstance.mongod实例上运行该命令。For a replica set, run the command on the primary. A majority of the data-bearing members must be available.对于副本集,在主服务器上运行该命令。大多数数据承载成员必须可用。For a sharded cluster, run the command on a对于分片集群,在mongosinstance.mongos实例上运行该命令。
"5.0"featureCompatibilityVersion is supported on MongoDB 5.0 and MongoDB 6.0 deployments only.featureCompatibilityVersion仅在MongoDB 5.0和MongoDB 6.0部署上受支持。
db.adminCommand( { setFeatureCompatibilityVersion: "5.0" } )
If run as part of the downgrade process from MongoDB 6.0 to MongoDB 5.0, you must also remove all persisted features that are incompatible with 5.0. See the appropriate downgrade procedures.如果作为从MongoDB 6.0到MongoDB 5.0降级过程的一部分运行,您还必须删除与5.0不兼容的所有持久功能。请参阅相应的降级程序。
Set Write Concern Timeout设置写入关注超时
The following example sets the optional write concern 以下示例将可选的写入关注wtimeout field to 5000 (5 seconds).wtimeout字段设置为5000(5秒)。
Note
Run the 对setFeatureCompatibilityVersion command against the admin database.admin数据库运行setFeatureCompatibilityVersion命令。
For a standalone, run the command on the standalone对于单机版,在单机版mongodinstance.mongod实例上运行该命令。For a replica set, run the command on the primary. A majority of the data-bearing members must be available.对于副本集,在主服务器上运行该命令。大多数数据承载成员必须可用。For a sharded cluster, run the command on a对于分片集群,在mongosinstance.mongos实例上运行该命令。
db.adminCommand( {
setFeatureCompatibilityVersion: "5.0",
writeConcern: { wtimeout: 5000 }
} )