Docs HomeMongoDB Manual

Compatibility Changes in MongoDB 6.0MongoDB 6.0中的兼容性更改

This page describes changes introduced in MongoDB 6.0 that can affect compatibility with older versions of MongoDB.本页介绍了MongoDB 6.0中引入的更改,这些更改可能会影响与旧版本MongoDB的兼容性。

MongoDB 6.0 is a Major Release, which means that it is supported for both MongoDB Atlas and on-premises deployments. MongoDB 6.0是一个主要版本,这意味着它同时支持MongoDB Atlas和本地部署。MongoDB 6.0 includes changes introduced in MongoDB Rapid Releases 5.1, 5.2, and 5.3. MongoDB 6.0包括在MongoDB Rapid Release 5.1、5.2和5.3中引入的更改。This page describes compatibility changes introduced in those Rapid Releases and MongoDB 6.0.本页介绍了Rapid Release和MongoDB 6.0中引入的兼容性更改。

To learn more about the differences between Major and Rapid releases, see MongoDB Versioning.要了解更多关于Major和Rapid版本之间的差异,请参阅MongoDB版本控制

Aggregation聚合

allowDiskUse Changes更改

Starting in MongoDB 6.0, pipeline stages that require more than 100 megabytes of memory to execute write temporary files to disk by default. 从MongoDB 6.0开始,需要超过100MB内存才能执行的管道阶段默认情况下会将临时文件写入磁盘。In earlier verisons of MongoDB, you must pass { allowDiskUse: true } to individual find and aggregate commands to enable this behavior.在MongoDB的早期版本中,必须将{ allowDiskUse: true }传递给单个findaggregate命令才能启用此行为。

Individual find and aggregate commands may override the allowDiskUseByDefault parameter by either:单独的findaggregate命令可以通过以下方式覆盖allowDiskUseByDefault参数:

  • Using { allowDiskUse: true } to allow writing temporary files out to disk when allowDiskUseByDefault is set to falseallowDiskUseByDefault设置为false时,使用{ allowDiskUse: true }允许将临时文件写入磁盘

  • Using { allowDiskUse: false } to prohibit writing temporary files out to disk when allowDiskUseByDefault is set to trueallowDiskUseByDefault设置为true时,使用{ allowDiskUse: false }禁止将临时文件写入磁盘

$$SEARCH_META Limitations局限性

Starting in MongoDB 6.0, the Atlas Search $$SEARCH_META aggregation variable can be used anywhere after a $search stage in any pipeline, but it cannot be used after the $lookup or $unionWith stage in any pipeline. 从MongoDB 6.0开始,Atlas Search$$SEARCH_META聚合变量可以在任何管道中$search阶段之后的任何位置使用,但不能在任何管道的$lookup$unionWith阶段之后使用。The $$SEARCH_META aggregation variable cannot be used in any subsequent stage after a $searchMeta stage.$$SEARCH_META聚合变量不能在$searchMeta阶段之后的任何后续阶段中使用。

Change Streams更改流

Starting in MongoDB 5.3, during range migration, change stream events are not generated for updates to orphaned documents.从MongoDB 5.3开始,在范围迁移过程中,不会为孤立文档的更新生成更改流事件。

Indexes索引

Last Remaining Shard Key Index Cannot be Dropped Inadvertently不能意外删除最后剩余的分片键索引

Starting in MongoDB 6.0, passing "*" to dropIndexes or db.collection.dropIndexes() drops all indexes except for the _id index and the last remaining shard key index, if one exists. 从MongoDB 6.0开始,将"*"传递给dropIndexesdb.collection.dropIndexes()将删除除_id索引和最后一个剩余的分片键索引(如果存在)之外的所有索引。Attempts to explicitly drop the last remaining shard key index raise an error.试图显式删除最后一个剩余的分片键索引会引发错误。

Existing Indexes Can Be Dropped During an Index Build在索引生成过程中可以删除现有索引

Starting in MongoDB 5.2, you can use dropIndexes or db.collection.dropIndexes() to drop existing indexes on the same collection even if there is an index build in progress. 从MongoDB 5.2开始,即使正在进行索引构建,也可以使用dropIndexesdb.collection.dropIndexes()来删除同一集合上的现有索引。In earlier versions, attempting to drop a different index during an in-progress index build results in a BackgroundOperationInProgressForNamespace error.在早期版本中,在正在进行的索引生成过程中尝试删除其他索引会导致BackgroundOperationInProgressForNamespace错误。

2dsphere Document Index Keys文档索引键

To prevent out of memory errors, indexMaxNumGeneratedKeysPerDocument limits the maximum number of 2dsphere index keys generated for a single document.为了防止内存不足错误,indexMaxNumGeneratedKeysPerDocument限制了为单个文档生成的2dsphere索引键的最大数量。

See indexMaxNumGeneratedKeysPerDocument.请参阅索引indexMaxNumGeneratedKeysPerDocument

Index Key Format索引键格式

Starting in MongoDB 6.0, a change to the unique index key format was introduced. 从MongoDB 6.0开始,引入了对唯一索引键格式的更改。If you create a unique index in MongoDB 6.0, the index won't work with MongoDB versions earlier than 5.3.2 or 5.0.7.如果您在MongoDB 6.0中创建了一个唯一的索引,那么该索引将不适用于5.3.2或5.0.7之前的MongoDB版本。

Legacy mongo Shell Removed已删除旧mongo外壳

The mongo shell is removed from MongoDB 6.0. mongo shell已从MongoDB 6.0中删除。The replacement is mongosh.替代者是mongosh

Platform Support平台支持

Starting in MongoDB 5.1.2 the following platforms are no longer supported:从MongoDB 5.1.2开始,不再支持以下平台:

Community Edition社区版

  • RHEL-72-s390x

Regular Expressions正则表达式

$regex Find Queries No Longer Ignore Invalid Regex查找查询不再忽略无效Regex

Starting in MongoDB 5.1, invalid $regex options options are no longer ignored. 从MongoDB 5.1开始,不再忽略无效的$regex optionsThis change makes $regex options more consistent with the use of $regex in the aggregate command and projection queries.此更改使$regex optionsaggregate命令和投影查询中$regex的使用更加一致。

$regex Schema Validation Error Behavior架构验证错误行为

Starting in MongoDB 5.1, if a collection has schema validation rules that contain invalid $regex options the server:从MongoDB 5.1开始,如果集合的架构验证规则包含无效的$regex options,则服务器:

  • Prevents all insert and update operations until the schema validation rules containing the invalid regex pattern are modified with the collMod command.在使用collMod命令修改包含无效正则表达式模式的架构验证规则之前,禁止所有插入和更新操作。

  • Writes a warning error to the mongod log file.将警告错误写入mongod日志文件。

Removed Operators删除的运算符

Starting in MongoDB 5.1, these legacy query operators are removed:从MongoDB 5.1开始,删除了这些遗留查询运算符:

Removed Operator删除的运算符Alternative可供替代的
$commentcursor.comment()
$explaincursor.explain()
$hintcursor.hint()
$maxcursor.max()
$maxTimeMScursor.maxTimeMS()
$mincursor.min()
$orderbycursor.sort()
$querySee Cursor Methods
$returnKeycursor.returnKey()
$showDiskLoccursor.showRecordId()
db.getLastError()See Legacy Opcodes Removed
db.getLastErrorObj()See Legacy Opcodes Removed
getLastErrorSee Legacy Opcodes Removed

Removed Options删除的选项

MongoDB 6.0 removes the --cpu mongod option.MongoDB 6.0删除了--cpu mongod选项。

Removed Parameters删除的参数

MongoDB 6.0 removes the following server parameters:MongoDB 6.0删除了以下服务器参数:

Removed Parameter删除的参数Description描述
--tlsFIPSModeThis option is removed from the MongoDB Community Edition. 此选项已从MongoDB社区版中删除。It is available in MongoDB Enterprise edition.它在MongoDB Enterprise版中提供。
FIPS was not a supported feature in MongoDB Community Edition. 在MongoDB Community Edition中,FIPS不是受支持的功能。If your installation made use of FIPS anyway, you will need to reconfigure your TLS/SSL connections before upgrading.如果您的安装仍然使用FIPS,则在升级之前需要重新配置TLS/SSL连接

TTL expireAfterSeconds Behavior When Set to NaN设置为NaN时的TTL expireAfterSeconds行为

Setting TTL expireAfterSeconds to NaN experiences a behavior change from MongoDB 4.4 to MongoDB 6.0 that affects initial sync from MongoDB 4.4 and earlier and mongorestore from MongoDB 4.4 and earlier. TTL expireAfterSeconds设置为NaN会经历从MongoDB 4.4到MongoDB 6.0的行为变化,这会影响MongoDB 4.4及更早版本的初始同步以及MongoDB 4.4和更早版本的mongorestorePerforming any of those actions causes an expireAfterSeconds of NaN to be treated as an expireAfterSeconds of 0. 执行任何这些操作都会导致NaNexpireAfterSeconds被视为0expireAfterSecondsImmediate document expiration may occur as a result.因此,文档可能会立即过期。

Replica Sets复制集

Assert Cluster Wide Write Concern is Set When Starting or Adding Shard启动或添加分片时设置断言集群范围的写入问题

Starting in MongoDB 5.1, when starting, restarting or adding a shard server with sh.addShard() the Cluster Wide Write Concern (CWWC) must be set.从MongoDB 5.1开始,当使用shaddHard()启动、重新启动或添加分片服务器时,必须设置集群范围写问题(CWWC)

If the CWWC is not set and the shard is configured such that the default write concern is { w : 1 } the shard server will fail to start or be added and returns an error.如果未设置CWWC,并且对shard进行了配置,使得默认的写入问题为{ w : 1 },则分片服务器将无法启动或添加,并返回错误。

See default write concern calculations for details on how the default write concern is calculated.有关如何计算默认写入问题的详细信息,请参阅默认写入问题计算

rs.reconfig Cluster Wide Write Concern Validation群集范围的写入问题验证

Starting in MongoDB 5.1, you must set the Cluster Wide Write Concern (CWWC) prior to issuing any reconfigs that would otherwise change the default write concern of the new replica set member.从MongoDB 5.1开始,在发布任何会更改新副本集成员的默认写入问题reconfigs之前,必须设置集群范围写入问题(CWWC)

Security安全

Intra-Cluster Authentication集群内身份验证

Starting in MongoDB 5.3, SCRAM-SHA-1 cannot be used for intra-cluster authentication. 从MongoDB 5.3开始,SCRAM-SHA-1不能用于集群内身份验证。Only SCRAM-SHA-256 is supported.仅支持SCRAM-SHA-256

In previous MongoDB versions, SCRAM-SHA-1 and SCRAM-SHA-256 can both be used for intra-cluster authentication, even if SCRAM is not explicitly enabled.在以前的MongoDB版本中,SCRAM-SHA-1和SCRAM-SHA-256都可以用于集群内身份验证,即使SCRAM没有明确启用。

FIPS Mode Defaults SCRAM-SHA-1 Authentication to OffFIPS模式将SCRAM-SHA-1身份验证默认为关闭

Starting in MongoDB 5.1, instances running in FIPS mode have the SCRAM-SHA-1 authentication mechanism disabled by default. You can enable the SCRAM-SHA-1 authentication mechanism with the setParameter.authenticationMechanisms command.从MongoDB 5.1开始,在FIPS模式下运行的实例默认禁用SCRAM-SHA-1身份验证机制。您可以使用setParameter.authenticationMechanisms命令启用SCRAM-SHA-1身份验证机制。

This change will not affect drivers which target MongoDB setFeatureCompatibilityVersion 4.0+.此更改不会影响以setFeatureCompatibilityVersion为目标的驱动程序。

Time Series Collections时间序列集合

Warning

If you create a sharded time series collection in MongoDB 5.1 or greater, downgrading to a version older than MongoDB 5.0.4 will result in data loss.如果您在MongoDB 5.1或更高版本中创建分片时间序列集合,降级到MongoDB 5.0.4之前的版本将导致数据丢失。

Before downgrading to a version older than 5.0.4, drop all sharded time series collections.在降级到5.0.4以前的版本之前,请删除所有分片的时间序列集合。

Secondary Indexes on Time Series Collections时间序列集合的辅助索引

If there are secondary indexes on time series collections and you need to downgrade the feature compatibility version (FCV), you must first drop any secondary indexes that are incompatible with the downgraded FCV. 如果时间序列集合上有辅助索引,并且需要降级功能兼容性版本(FCV),则必须首先删除与降级的FCV不兼容的所有辅助索引。See setFeatureCompatibilityVersion.请参阅setFeatureCompatibilityVersion

General Changes一般变更

Deprecations弃用

Deprecated已弃用Description描述
db.collection.reIndex()The db.collection.reIndex() method is deprecated in MongoDB v6.0.在MongoDB v6.0中,不赞成使用db.collection.reIndex()方法。
reIndexThe reIndex command is deprecated in MongoDB v6.0.reIndex命令在MongoDB v6.0中已被弃用。
Simple Network Management Protocol (SNMP)简单网络管理协议(SNMP)Starting in MongoDB 6.0, SNMP is deprecated and will be removed in the next release. 从MongoDB 6.0开始,SNMP已被弃用,并将在下一版本中删除。To monitor your deployment, use MongoDB Ops Manager.要监控您的部署,请使用MongoDB Ops Manager

$mod Error Behavior错误行为

Starting in MongoDB 5.1 (and 5.0.4 and 4.4.10), the $mod operator returns an error if the divisor or remainder values evaluate to certain values. 从MongoDB 5.1(以及5.0.4和4.4.10)开始,如果divisorremainder值评估为特定值,$mod运算符将返回错误。See $mod behavior.请参阅$mod行为

Legacy Opcodes Removed已删除旧操作码

MongoDB 6.0 removes support for the following legacy opcodes and database commands:MongoDB 6.0删除了对以下遗留操作码和数据库命令的支持:

Warning

Upgrade Drivers升级驱动程序

To avoid disruption due to the removal of these opcodes, upgrade your driver to the latest version.为了避免由于删除这些操作码而造成的中断,请将驱动程序升级到最新版本

If you attempt to connect to a MongoDB 3.4 or older mongod instance with a MongoDB 5.1 or newer mongo shell, you will receive an error message like the following:如果您尝试使用MongoDB 5.1或更新的mongo shell连接到MongoDB 3.4或更旧的mongod实例,您将收到如下错误消息:

Connection handshake failed. Is your mongod 3.4 or older?
:: caused by :: network error while attempting to run command
'isMaster' on host '127.0.0.1:27017'

mongod Responses to Legacy Opcodesmongod对遗留操作码的响应

Since MongoDB 3.6, MongoDB drivers have used OP_MSG instead of OP_QUERY and the other legacy opcodes and commands.自MongoDB 3.6以来,MongoDB驱动程序使用了OP_MSG,而不是OP_QUERY和其他遗留操作码和命令。

Starting in MongoDB 6.0:在MongoDB 6.0中启动:

Note

OP_QUERY RPC Commands

The OP_QUERY RPC protocol may be used with the following commands:OP_QUERY RPC协议可以与以下命令一起使用:

  • _isSelf

  • authenticate

  • buildinfo

  • buildInfo

  • hello

  • ismaster

  • isMaster

  • saslContinue

  • saslStart

All other commands will be rejected if issued as OP_QUERY.如果作为OP_QUERY发出,则所有其他命令都将被拒绝。

Removed Deprecated Array and String Functions for Server-Side JavaScript删除了服务器端JavaScript的不推荐的数组和字符串函数

MongoDB 6.0 upgrades the internal JavaScript engine used for server-side JavaScript, $accumulator, $function, and $where expressions and from MozJS-60 to MozJS-91. MongoDB 6.0升级了用于服务器端JavaScript$accumulator$function$where表达式的内部JavaScript引擎,并从MozJS-60升级到MozJS-91。Several deprecated, non-standard array and string functions that existed in MozJS-60 are removed in MozJS-91.MozJS-60中存在的一些不推荐使用的非标准数组和字符串函数在MozJS-91中被删除。

For the complete list of removed array and string functions, see the next sections on this page.有关已删除的数组和字符串函数的完整列表,请参阅本页的下一节。

Note

Only Static Functions are Removed仅删除静态函数

Only static JavaScript functions are removed. 仅删除静态JavaScript函数。Prototype function equivalents of the removed functions can still be used.删除的函数的原型函数等价物仍然可以使用。

For example:例如:

  • Array.concat(<array1>, <array2>) is a static function and no longer works in MongoDB 6.0.是一个静态函数,不再适用于MongoDB 6.0。

  • <array1>.concat(<array2>) is a prototype function and still works in MongoDB 6.0.是一个原型函数,仍然可以在MongoDB 6.0中使用。

This behavior applies to both removed array and removed string functions.此行为适用于已删除的数组和已删除的字符串函数。

Removed Array Functions删除了数组函数

Starting in MongoDB 6.0, the following array functions are removed and cannot be used in server-side JavaScript with $accumulator, $function, and $where expressions:从MongoDB 6.0开始,以下数组函数将被删除,并且不能在带有$accumulator$function$where表达式的服务器端JavaScript中使用:

  • Array.concat

  • Array.every

  • Array.filter

  • Array.forEach

  • Array.indexOf

  • Array.join

  • Array.lastIndexOf

  • Array.map

  • Array.pop

  • Array.push

  • Array.reduce

  • Array.reduceRight

  • Array.reverse

  • Array.shift

  • Array.slice

  • Array.some

  • Array.sort

  • Array.splice

  • Array.unshift

Removed String Functions删除了字符串函数

Starting in MongoDB 6.0, the following array functions are removed and cannot be used in server-side JavaScript with $accumulator, $function, and $where expressions:从MongoDB 6.0开始,以下数组函数将被删除,并且不能在带有$accumulator$function$where表达式的服务器端JavaScript中使用:

  • String.charAt

  • String.charCodeAt

  • String.concat

  • String.contains

  • String.endsWith

  • String.includes

  • String.indexOf

  • String.lastIndexOf

  • String.localeCompare

  • String.match

  • String.normalize

  • String.replace

  • String.search

  • String.slice

  • String.split

  • String.startsWith

  • String.substr

  • String.substring

  • String.toLocaleLowerCase

  • String.toLocaleUpperCase

  • String.toLowerCase

  • String.toUpperCase

  • String.trim

  • String.trimLeft

  • String.trimRight

Default db.stats() Settings默认db.stats()设置

Starting in MongoDB 6.0, the dbStats command and the db.stats() method only report free space assigned to collections if the freeStorage parameter is set to 1.从MongoDB 6.0开始,如果freeStorage参数设置为1,则dbStats命令和db.stats()方法只报告分配给集合的可用空间。

Index Filters and Collations索引筛选器和排序规则

Starting in MongoDB 6.0, an index filter uses the collation previously set using the planCacheSetFilter command.从MongoDB 6.0开始,索引筛选器使用之前使用planCacheSetFilter命令设置的排序规则

Arrays in Collections and Views with distinct Command集合和视图中具有distinct命令的数组

Starting in MongoDB 6.0, the distinct command returns the same results for collections and views when using arrays.从MongoDB 6.0开始,distinct命令在使用数组时为集合和视图返回相同的结果。

See Arrays in Collections and Views.请参见集合和视图中的数组

Downgrade Considerations降级注意事项

The following sections provide information for removing backward-incompatible features from your deployment. 以下部分提供了有关从部署中删除向后不兼容功能的信息。If you are downgrading from MongoDB 6.0 to an earlier version, review the following sections to ensure that your deployment runs successfully after downgrading.如果您正在从MongoDB 6.0降级到早期版本,请查看以下部分,以确保降级后您的部署能够成功运行。

Clustered Collections群集集合

Starting in MongoDB 5.3, if you are using clustered collections, you must drop those collections before you can downgrade to an earlier MongoDB version.从MongoDB 5.3开始,如果您使用集群集合,则必须先删除这些集合,然后才能降级到早期的MongoDB版本。

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开始,如果需要降级功能兼容性版本,请确保禁用集群到集群的复制和用户写阻塞。

See Cluster-to-Cluster Sync and User Write Blocking.请参阅群集到群集同步和用户写入阻止

Time Series Collections时间序列集合

You must drop time series collections before downgrading:降级前必须删除时间序列集合:

  • MongoDB 6.0 or later to MongoDB 5.0.7 or earlier.MongoDB 6.0或更高版本到MongoDB 5.0.7或更早版本。

  • MongoDB 5.3 to MongoDB 5.0.5 or earlier.MongoDB 5.3到MongoDB 5.0.5或更早版本。

See Time Series Collections.请参阅时间序列集合

Cluster Parameters群集参数

Starting in MongoDB 6.0, ensure that all setClusterParameter operations have completed. 从MongoDB 6.0开始,确保所有setClusterParameter操作都已完成。fCV downgrade cannot occur successfully if there are any ongoing setClusterParameter operations on sharded clusters.如果在分片集群上有任何正在进行的setClusterParameter操作,则降级无法成功进行。

SELinux Policy DataSELinux策略数据

Starting in MongoDB 5.1, you must run the following command from the directory into which the SELinux policy was previously cloned before you can downgrade to an earlier MongoDB version:从MongoDB 5.1开始,您必须在之前克隆SELinux策略的目录中运行以下命令,然后才能降级到早期的MongoDB版本:

sudo make uninstall

Key Management Interoperability Protocol (KMIP) Settings密钥管理互操作性协议(KMIP)设置

Starting in MongoDB 5.3 Enterprise, if you are using the following KMIP settings, you must remove them from the configuration file before you can downgrade to an earlier MongoDB version:从MongoDB 5.3 Enterprise开始,如果您使用以下KMIP设置,则必须将其从配置文件中删除,然后才能降级到早期的MongoDB版本:

Time-based Retention of Change Streams Pre- and Post-Image Collections基于时间的变化流图像前后采集保留

Starting in MongoDB 6.0, if you are using changeStreamOptions.preAndPostImages.expireAfterSeconds to control time-based retention of change streams pre- and post-image collections, you must ensure there are no active setClusterParameter operations when downgrading.从MongoDB 6.0开始,如果您使用changeStreamOptions.preAndPostImages.expireAfterSeconds来控制更改流映像前和映像后集合的基于时间的保留,则必须确保降级时没有活动的setClusterParameter操作。

Audit Log Encryption Settings审核日志加密设置

Starting in MongoDB 6.0 Enterprise, if you are using audit log encryption, you must remove the following settings from the configuration file before you can downgrade to an earlier MongoDB version:从MongoDB 6.0 Enterprise开始,如果您使用审计日志加密,则必须从配置文件中删除以下设置,然后才能降级到早期的MongoDB版本:

Existing encrypted audit logs remain encrypted, and you can keep any procedures you have developed for storage and processing of encrypted logs.现有的加密审核日志仍然是加密的,您可以保留为存储和处理加密日志而开发的任何过程。

See Audit Log.请参阅审核日志

Change Streams with Document Pre- and Post-Images使用文档前后图像更改流

Starting in MongoDB 6.0, if you are using document pre- and post-images for change streams, you must disable changeStreamPreAndPostImages for each collection using the collMod command before you can downgrade to an earlier MongoDB version.从MongoDB 6.0开始,如果您对更改流使用文档前和后图像,则必须使用collMod命令为每个集合禁用changeStreamPreAndPostImages,然后才能降级到早期的MongoDB版本。

Change Streams with Expanded Events使用扩展的事件更改流

If your application uses change streams, ensure that it does not require the showExpandedEvents option, which will not be available after downgrade.如果您的应用程序使用更改流,请确保它不需要showExpandedEvents选项,该选项在降级后将不可用。

LDAP with srv: and srv_raw:带有srv:srv_raw:的LDAP

If your cluster's configuration is using the new "srv:" or "srv_raw:" URL types in its LDAP configuration, it will be unable to restart after a downgrade. 如果集群的配置在LDAP配置中使用新的"srv:""srv_raw:"URL类型,则降级后将无法重新启动。Remove the new URL types from your cluster's configuration before or downgrading.在降级之前,请从群集的配置中删除新的URL类型。

Collections with Encrypted Fields具有加密字段的集合

You must drop collections that use encrypted fields before you can complete the fCV downgrade. 必须先删除使用加密字段的集合,然后才能完成fCV降级。The downgrade will not complete if there are collections using encryptedFields.如果存在使用encryptedFields的集合,则降级将不会完成。