Docs HomeMongoDB Manual

rename Event事件

Summary摘要

rename

New in version 4.0.1. 4.0.1版新增。

A rename event occurs when a collection is renamed.重命名集合时会发生rename事件。

Description描述

Field字段Type类型Description描述
_idDocumentA 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. 恢复更改流时,此值用作resumeAfter参数的resumeTokenThe _id object has the following form: _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恢复更改流的示例,请参阅恢复更改流
clusterTimeTimestampThe timestamp from the oplog entry associated with the event.与事件关联的oplog条目中的时间戳。
Change stream event notifications associated with a multi-document transaction all have the same clusterTime value: the time when the transaction was committed.多文档事务关联的更改流事件通知都具有相同的clusterTime值:事务提交的时间。
On sharded clusters, events with the same clusterTime may not all relate to the same transaction. Some events don't relate to a transaction at all.在分片集群上,具有相同clusterTime的事件可能并不都与同一事务相关。有些事件根本与事务无关。
To identify events for a single transaction, you can use the combination of lsid and txnNumber in the change stream event document. 要识别单个事务的事件,可以在变更流事件文档中使用lsidtxnNumber的组合。
New in version 4.0. 4.0版新增。
collectionUUIDUUIDUUID identifying the collection where the change occurred. 标识发生更改的集合。
New in version 6.0. 6.0版新增。
lsiddocumentThe identifier for the session associated with the transaction.与事务关联的会话的标识符。
Only present if the operation is part of a multi-document transaction. 仅当操作是多文档事务的一部分时才显示。
New in version 4.0. 4.0版新增。
nsdocumentThe namespace (database and or collection) affected by the event. 受事件影响的命名空间(数据库和/或集合)。
ns.dbstringThe name of the database where the event occurred. 发生事件的数据库的名称。
ns.collstringThe name of the collection where the event occurred. 发生事件的集合的名称。
operationDescriptiondocumentAdditional 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.
dropTarget
UUIDUUID of the collection that was dropped in the rename operation. 在重命名操作中删除的集合的UUID
New in version 6.0. 6.0版新增。
operationDescription.
to
documentThe new namespace of the collection after the rename. 重命名后集合的新命名空间。
New in version 6.0. 6.0版新增。
operationDescription.
to.coll
documentThe new name of the collection after the rename. 重命名后集合的新名称。
New in version 6.0. 6.0版新增。
operationDescription.
to.db
documentThe new name of the database after the rename. 重命名后数据库的新名称。
New in version 6.0. 6.0版新增。
operationTypestringThe type of operation that the change notification reports.更改通知报告的操作类型。
Returns a value of rename for these change events. 返回这些更改事件的值rename
todocumentThe new namespace of the collection after the rename. 重命名后集合的新命名空间。
to.colldocumentThe new name of the collection after the rename. 重命名后集合的新名称。
to.dbdocumentThe new name of the database after the rename. 重命名后数据库的新名称。
txnNumberNumberLongTogether with the lsid, a number that helps uniquely identify a transction.lsid一起,是一个有助于唯一识别事务的数字。
Only present if the operation is part of a multi-document transaction. 仅当操作是多文档事务的一部分时才显示。
New in version 4.0. 4.0版新增。
wallTimeISODateThe server date and time of the database operation. 数据库操作的服务器日期和时间。wallTime differs from clusterTime in that clusterTime is a timestamp taken from the oplog entry associated with the database operation event. wallTimeclusterTime的不同之处在于,clusterTime是从与数据库操作事件关联的oplog条目中获取的时间戳。
New in version 6.0. 6.0版新增。

Behavior行为

Expanded Event Information扩展的事件信息

Changed in version 6.0.6.0版更改。

Starting in MongoDB 6.0, when the showExpandedEvents option is set to true for the change stream, the rename event includes an operationDescription document. 从MongoDB 6.0开始,当更改流的showExpandedEvents选项设置为true时,rename事件包括一个operationDescription文档。This document provides a to field showing the changed database and collection and a dropTarget field indicating whether the rename operation removed the collection before the rename.此文档提供了一个显示更改后的数据库和集合的to字段,以及一个指示rename操作是否在重命名前删除了集合的dropTarget字段。

Example实例

The following example illustrates a rename event:以下示例说明了rename事件:

{
"_id": { <Resume Token> },
"operationType": "rename",
"clusterTime": <Timestamp>,
"wallTime": <ISODate>,
"ns": {
"db": "engineering",
"coll": "users"
},
"to": {
"db": "engineering",
"coll": "people"
},
"operationDescription": {
"to": {
"db": "engineering",
"coll": "people"
}
}
}

A rename event leads to an invalidate event for change streams opened against its ns collection or to collection.rename事件会导致针对其ns集合或to集合打开的更改流的无效事件