Compatibility Changes in MongoDB 6.0MongoDB 6.0中的兼容性更改
On this page
Aggregation聚合Change Streams更改流Indexes索引Legacy已删除旧mongo
Shell Removedmongo
外壳Platform Support平台支持Regular Expressions正则表达式Removed Operators删除的运算符Removed Options删除的选项Removed Parameters删除的参数TTL设置为expireAfterSeconds
Behavior When Set toNaN
NaN
时的TTLexpireAfterSeconds
行为Replica Sets复制集Security安全Time Series Collections时间序列集合General Changes一般变更Downgrade Considerations降级注意事项
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 在MongoDB的早期版本中,必须将{ allowDiskUse: true }
to individual find
and aggregate
commands to enable this behavior.{ allowDiskUse: true }
传递给单个find
和aggregate
命令才能启用此行为。
Individual 单独的find
and aggregate
commands may override the allowDiskUseByDefault
parameter by either:find
和aggregate
命令可以通过以下方式覆盖allowDiskUseByDefault
参数:
-
Using当{ allowDiskUse: true }
to allow writing temporary files out to disk whenallowDiskUseByDefault
is set tofalse
allowDiskUseByDefault
设置为false
时,使用{ allowDiskUse: true }
允许将临时文件写入磁盘 -
Using当{ allowDiskUse: false }
to prohibit writing temporary files out to disk whenallowDiskUseByDefault
is set totrue
allowDiskUseByDefault
设置为true
时,使用{ allowDiskUse: false }
禁止将临时文件写入磁盘
$$SEARCH_META
Limitations局限性
Starting in MongoDB 6.0, the Atlas Search 从MongoDB 6.0开始,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. $$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 从MongoDB 6.0开始,将"*"
to dropIndexes
or db.collection.dropIndexes()
drops all indexes except
for the _id
index and the last remaining shard key index, if one exists. "*"
传递给dropIndexes
或db.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 从MongoDB 5.2开始,即使正在进行索引构建,也可以使用dropIndexes
or db.collection.dropIndexes()
to drop existing indexes on the same collection even if there is an index build in progress. dropIndexes
或db.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
外壳
mongo
Shell RemovedThe 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 从MongoDB 5.1开始,不再忽略无效的$regex options
options are no longer ignored. $regex options
。This change makes 此更改使$regex options
more consistent with the use of $regex
in the aggregate
command and projection queries.$regex options
与aggregate
命令和投影查询中$regex
的使用更加一致。
$regex
Schema Validation Error Behavior架构验证错误行为
Starting in MongoDB 5.1, if a collection has schema validation rules that contain invalid 从MongoDB 5.1开始,如果集合的架构验证规则包含无效的$regex options
the server:$regex options
,则服务器:
Removed Operators删除的运算符
Starting in MongoDB 5.1, these legacy query operators are removed:从MongoDB 5.1开始,删除了这些遗留查询运算符:
$comment | cursor.comment() |
$explain | cursor.explain() |
$hint | cursor.hint() |
$max | cursor.max() |
$maxTimeMS | cursor.maxTimeMS() |
$min | cursor.min() |
$orderby | cursor.sort() |
$query | See Cursor Methods |
$returnKey | cursor.returnKey() |
$showDiskLoc | cursor.showRecordId() |
db.getLastError() | See Legacy Opcodes Removed |
db.getLastErrorObj() | See Legacy Opcodes Removed |
getLastError | See Legacy Opcodes Removed |
Removed Options删除的选项
MongoDB 6.0 removes the MongoDB 6.0删除了--cpu
mongod
option.--cpu
mongod
选项。
Removed Parameters删除的参数
MongoDB 6.0 removes the following server parameters:MongoDB 6.0删除了以下服务器参数:
--tlsFIPSMode |
TTL expireAfterSeconds
Behavior When Set to NaN
设置为NaN
时的TTL expireAfterSeconds
行为
expireAfterSeconds
Behavior When Set to NaN
Setting TTL 将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. expireAfterSeconds
设置为NaN
会经历从MongoDB 4.4到MongoDB 6.0的行为变化,这会影响MongoDB 4.4及更早版本的初始同步以及MongoDB 4.4和更早版本的mongorestore
。Performing any of those actions causes an 执行任何这些操作都会导致expireAfterSeconds
of NaN
to be treated as an expireAfterSeconds
of 0
. NaN
的expireAfterSeconds
被视为0
的expireAfterSeconds
。Immediate 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 从MongoDB 5.1开始,当使用sh.addShard()
the Cluster Wide Write Concern (CWWC) must be set.shaddHard()
启动、重新启动或添加分片服务器时,必须设置集群范围写问题(CWWC)。
If the 如果未设置CWWC,并且对shard进行了配置,使得默认的写入问题为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.{ 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 从MongoDB 5.1开始,在发布任何会更改新副本集成员的默认写入问题的reconfigs
that would otherwise change the default write concern of the new replica set member.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时间序列集合
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弃用
db.collection.reIndex() | db.collection.reIndex() method is deprecated in MongoDB v6.0.db.collection.reIndex() 方法。 |
reIndex | reIndex command is deprecated in MongoDB v6.0.reIndex 命令在MongoDB v6.0中已被弃用。 |
$mod
Error Behavior错误行为
Starting in MongoDB 5.1 (and 5.0.4 and 4.4.10), the 从MongoDB 5.1(以及5.0.4和4.4.10)开始,如果$mod
operator returns an error if the divisor
or remainder
values evaluate to certain values. divisor
或remainder
值评估为特定值,$mod
运算符将返回错误。See $mod behavior.请参阅$mod
行为。
Legacy Opcodes Removed已删除旧操作码
MongoDB 6.0 removes support for the following legacy opcodes and database commands:MongoDB 6.0删除了对以下遗留操作码和数据库命令的支持:
-
getLastError
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 如果您尝试使用MongoDB 5.1或更新的mongo shell连接到MongoDB 3.4或更旧的mongod
instance with a MongoDB 5.1 or newer mongo
shell, you will receive an error message like the following: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中启动:
Removed Deprecated Array and String Functions for Server-Side JavaScript删除了服务器端JavaScript的不推荐的数组和字符串函数
MongoDB 6.0 upgrades the internal JavaScript engine used for server-side JavaScript, MongoDB 6.0升级了用于服务器端JavaScript、$accumulator
, $function
, and $where
expressions and from MozJS-60 to MozJS-91. $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.有关已删除的数组和字符串函数的完整列表,请参阅本页的下一节。
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 从MongoDB 6.0开始,以下数组函数将被删除,并且不能在带有$accumulator
, $function
, and $where
expressions:$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 从MongoDB 6.0开始,以下数组函数将被删除,并且不能在带有$accumulator
, $function
, and $where
expressions:$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()
设置
db.stats()
SettingsStarting in MongoDB 6.0, the 从MongoDB 6.0开始,如果freeStorage参数设置为1,则dbStats
command and the db.stats()
method only report free space assigned to collections if the freeStorage parameter is set to 1.dbStats
命令和db.stats()
方法只报告分配给集合的可用空间。
Index Filters and Collations索引筛选器和排序规则
Starting in MongoDB 6.0, an index filter uses the collation previously set using the 从MongoDB 6.0开始,索引筛选器使用之前使用planCacheSetFilter
command.planCacheSetFilter
命令设置的排序规则。
Arrays in Collections and Views with distinct
Command集合和视图中具有distinct
命令的数组
distinct
CommandStarting in MongoDB 6.0, the 从MongoDB 6.0开始,distinct
command returns the same results for collections and views when using arrays.distinct
命令在使用数组时为集合和视图返回相同的结果。
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 从MongoDB 6.0开始,确保所有setClusterParameter
operations have completed. 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 从MongoDB 6.0开始,如果您使用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.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 从MongoDB 6.0开始,如果您对更改流使用文档前和后图像,则必须使用collMod命令为每个集合禁用collMod
command before you can downgrade to an earlier MongoDB version.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
srv:
and srv_raw:
If your cluster's configuration is using the new 如果集群的配置在LDAP配置中使用新的"srv:"
or "srv_raw:"
URL types in its LDAP configuration, it will be unable to restart after a downgrade. "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
的集合,则降级将不会完成。