Database Manual / Change Streams / Change Events

create Event事件

Summary摘要

create

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

A create event occurs when a collection is created on a watched database and the change stream has the showExpandedEvents option set to true.当在监视的数据库上创建集合并且更改流的showExpandedEvents选项设置为true时,会发生create事件。

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. BSON对象,用作更改流事件的标识符。在恢复更改流时,此值用作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恢复更改流的示例,请参阅恢复更改流

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. 具有相同clusterTime的事件可能并不都与同一事务相关。有些事件根本与事务无关。从MongoDB 8.0开始,这可能适用于任何部署上的事件。In previous versions, this behavior was possible only for events on a sharded cluster.在以前的版本中,这种行为仅适用于分片集群上的事件。

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

If the change occurred on a collection, collectionUUID indicates the collection's UUID. If the change occurred on a view, collectionUUID doesn't exist.如果更改发生在集合上,则collectionUUID表示集合的UUID。如果更改发生在视图上,则collectionUUID不存在。

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

lsiddocument文档

The identifier for the session associated with the transaction.与事务关联的会话的标识符。

Only present if the operation is part of a multi-document transaction.仅当操作是多文档事务的一部分时才存在。

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.发生事件的数据库的名称。

nsTypestring字符串

Shows the namespace type of the collection created by this event.显示此事件创建的集合的命名空间类型。

"collection"
Indicates the event creates a collection.表示该事件创建了一个集合。
"timeseries"
Indicates the event creates a timeseries collection.表示该事件创建了一个时间序列集合。
"view"
Indicates the event creates a non-timeseries view.表示该事件创建了一个非时间序列视图。

New in version 8.1.在版本8.1中新增。 (also available in 8.0.5).(也可在8.0.5中使用)。

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.
idIndex
document文档

The default _id index for a new collection.新集合的默认_id索引。

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

operationTypestring字符串

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

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

txnNumberNumberLong

Together with the lsid, a number that helps uniquely identify a transction.lsid一起,一个有助于唯一标识事务的数字。

Only present if the operation is part of a multi-document transaction.仅当操作是多文档事务的一部分时才存在。

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 shows a create event:以下示例显示了create事件:

{
"_id": { <ResumeToken> },
"operationType": "create",
"clusterTime": Timestamp({ t: 1654894547, i: 24 }),
"collectionUUID": UUID("98046a1a-b649-4e5b-9c75-67594221ce19"),
"wallTime": ISODate("2022-06-10T20:55:47.947Z"),
"ns": {
"db": "test",
"coll": "names"
},
"operationDescription": {
"idIndex": { "v": 2, "key": { _id: 1 }, "name": "_id_" }
}
}