Database Manual / Change Streams / Change Events

invalidate Event事件

Summary摘要

invalidate
An invalidate event occurs when an operation renders the change stream invalid. For example, a change stream opened on a collection that was later dropped or renamed would cause an invalidate event.当操作使更改流无效时,会发生invalidate事件。例如,在集合上打开的更改流后来被删除或重命名,将导致invalidate事件。

Description描述

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

A BSON object which serves as an identifier for the change stream event. This value is used as the resumeToken for the resumeAfter parameter when resuming a change stream. The _id object has the following form:BSON对象,用作更改流事件的标识符。在恢复更改流时,此值用作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. See Resume Tokens for the full list of _data types._data类型取决于MongoDB版本,在某些情况下,还取决于更改流打开或恢复时的功能兼容性版本(FCV)。有关_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. 由于oplog大小的限制多文档事务可能会创建多个oplog条目。In a transaction, change stream events staged in a given oplog entry share the same clusterTime.在事务中,给定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中的更改。

operationTypestring字符串

The type of operation that the change notification reports.更改通知报告的操作类型。

Returns a value of invalidate for these change events.返回这些更改事件的invalidate值。

wallTimeISODate

The 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中新增。

Example示例

The following example illustrates an invalidate event:以下示例说明了invalidate事件:

{
"_id": { <Resume Token> },
"operationType": "invalidate",
"clusterTime": <Timestamp>,
"wallTime": <ISODate>
}

Change streams opened on collections raise an invalidate event when a drop, rename, or dropDatabase operation occurs that affects the watched collection.当发生影响所监视集合的droprenamedropDatabase操作时,在集合上打开的更改流会引发invalidate事件。

Change streams opened on databases raise an invalidate event when a dropDatabase event occurs that affects the watched database.当发生影响所监视数据库的dropDatabase事件时,在数据库上打开的更改流会引发invalidate事件。

invalidate events close the change stream cursor.事件关闭更改流游标。

You cannot use resumeAfter to resume a change stream after an invalidate event (for example, a collection drop or rename) closes the stream. Instead, you can use startAfter to start a new change stream after an invalidate event.invalidate事件(例如,集合删除或重命名)关闭更改流后,您不能使用resumeAfter来恢复更改流。相反,您可以使用startAfterinvalidate事件后启动新的更改流。