Database Manual / Change Streams / Change Events

reshardCollection Event事件

Summary摘要

reshardCollection

New in version 6.1.在版本6.1中新增。 (Also available in 6.0.14)(6.0.14中也有)

A reshardCollection event occurs when:reshardCollection事件在以下情况下发生:

  • The shard key for a collection and the distribution of your data is changed, and集合的分片键和数据的分布发生了变化,并且
  • The change stream has showExpandedEvents set to true.更改流showExpandedEvents设置为true

Description描述

Field字段Type类型Description描述
_idDocument文档

A BSON object which serves as an identifier for the change stream event. BSON对象,用作更改流事件的标识符。This value is used as the resumeToken for the resumeAfter parameter when resuming a change stream. The _id object has the following form:在恢复更改流时,此值用作resumeAfter参数的resumeToken_id对象具有以下形式:

{
"_data" : <BinData|hex string>
}

The _data type depends on the MongoDB versions and, in some cases, the feature compatibility version (FCV) at the time of the change stream's opening or resumption. _data类型取决于MongoDB版本,在某些情况下,还取决于更改流打开或恢复时的功能兼容性版本(FCV)See Resume Tokens for the full list of _data types.有关_data类型的完整列表,请参阅恢复令牌

For an example of resuming a change stream by resumeToken, see Resume a Change Stream.有关通过resumeToken恢复更改流的示例,请参阅恢复更改流

clusterTimeTimestamp

clusterTime is the timestamp from the oplog entry associated with the event.是与事件关联的oplog条目的时间戳。

Due to oplog size limits, multi-document transactions may create multiple oplog entries. In a transaction, change stream events staged in a given oplog entry share the same clusterTime.由于oplog大小的限制多文档事务可能会创建多个oplog条目。在事务中,给定oplog条目的变更流事件共享相同的clusterTime

Events with the same clusterTime may not all relate to the same transaction. Some events don't relate to a transaction at all. Starting in MongoDB 8.0, this may be true for events on any deployment. In previous versions, this behavior was possible only for events on a sharded cluster.具有相同clusterTime的事件可能并不都与同一事务相关。有些事件根本与事务无关。从MongoDB 8.0开始,这可能适用于任何部署上的事件。在以前的版本中,这种行为仅适用于分片集群上的事件。

To identify events for a single transaction, you can use the combination of lsid and txnNumber in the change stream event document.要识别单个事务的事件,可以在更改流事件文档中使用lsidtxnNumber的组合。

Changed in version 8.0.在版本8.0中的更改。

collectionUUIDUUID

UUID identifying the collection where the change occurred.标识发生更改的集合的UUID。

New in version 6.0.在版本6.0中新增。

nsDocument文档

The namespace (database and or collection) affected by the event.受事件影响的命名空间(数据库和/或集合)。

ns.collString字符串

The name of the collection where the event occurred.发生事件的集合的名称。

ns.dbString字符串

The name of the database where the event occurred.发生事件的数据库的名称。

operationDescriptionDocument文档

Additional information on the change operation.有关更改操作的其他信息。

This document and its subfields only appears when the change stream uses expanded events.此文档及其子字段仅在更改流使用扩展事件时显示。

New in version 6.0.在版本6.0中新增。

operationDescription.
reshardUUID
UUID

UUID that identifies the resharding operation.标识重新标记操作的UUID。

New in version 6.1.在版本6.1中新增。

operationDescription. | shardKeyDocument文档

The shard key for the collection where the change occurred.发生更改的集合的分片键

New in version 6.0.在版本6.0中新增。

operationDescription. | oldShardKeyDocument文档

The shard key for the collection that changed.更改的集合的分片键

New in version 6.1.在版本6.1中新增。

operationDescription. | uniqueBoolean布尔值

This has a value of true if the collection was sharded with a unique shard key.如果集合使用唯一的分片键进行分片,则此值为true

New in version 6.0.在版本6.0中新增。

operationDescription. | numInitialChunksNumberLong

Number of chunks created on each shard during a shardCollection operation.shardCollection操作期间在每个分片上创建的块数。

New in version 6.0.在版本6.0中新增。

Starting in MongoDB 8.2, resharding operations ignore the numInitialChunks setting when the shard key contains a hashed prefix. Instead, MongoDB deterministically splits the hashed key space among recipients, using the same approach as initial chunk creation for empty hashed collections.从MongoDB 8.2开始,当分片键包含哈希前缀时,重新标记操作会忽略numInitialChunks设置。相反,MongoDB使用与空哈希集合的初始块创建相同的方法,在接收者之间确定性地分割哈希键空间。

operationDescription.
collation
Document文档

Collation document used for the shard key index.用于分片键索引的排序规则文档。

New in version 6.1.在版本6.1中新增。

operationDescription.
zones
Array数组

The zones added for the new shard key.为新分片键添加的区域。

New in version 6.1.在版本6.1中新增。

Example示例

The following example shows a reshardCollection event:以下示例显示了reshardCollection事件:

{
"_id": { <ResumeToken> },
"operationType": "reshardCollection",
"collectionUUID": 0,
"ns": {"db": "reshard_collection_event", "coll": "coll"},
"operationDescription": {
"reshardUUID": 0,
"shardKey": {"newKey": 1},
"oldShardKey": {"_id": 1},
"unique": false,
"numInitialChunks": Long(1),
"collation": {"locale": "simple"},
"zones": [
{"zone": "zone1", "min": {"newKey": {"$minKey": 1}}, "max": {"newKey": {"$maxKey": 1}}}
]
}
}