Docs HomeMongoDB Manual

modify Event

On this page本页内容

Summary摘要

modify

New in version 6.0. 6.0版新增。

A modify event occurs when a collection is modified, such as when the collMod command adds or remove options from a collection or view. 修改集合时会发生modify事件,例如collMod命令在集合或视图中添加或删除选项时。This event is received only if the change stream has the showExpandedEvents option set to true.只有当更改流的showExpandedEvents选项设置为true时,才会接收到此事件。

Note

Disambiguation消除歧义

To learn more about events that occur when individual documents are updated, see the update event.要了解有关更新单个文档时发生的事件的详细信息,请参阅update事件。

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. 在分片集群上,具有相同clusterTime的事件可能并不都与同一事务相关。Some events don't relate to a transaction at all.有些事件根本与事务无关。
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.
index
documentThe index that was modified. 已修改的索引。
New in version 6.0. 6.0版新增。
operationDescription.
indexes
arrayAn array of documents listing the indexes that were changed by the operation.列出操作更改的索引的文档数组。
operationTypestringThe type of operation that the change notification reports.更改通知报告的操作类型。
Returns a value of modify for these change events. 返回这些更改事件的modify值。
stateBeforeChangedocumentDocument shows collection and index options before the operation changed them. 文档显示在操作更改集合和索引选项之前的这些选项。
stateBeforeChange.
collectionOptions
documentDocument shows collection options before the operation changed them. 文档显示在操作更改集合选项之前的集合选项。
stateBeforeChange.
indexOptions
documentDocument shows index options before the operation changed them. 文档显示操作更改索引选项之前的索引选项。
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版新增。

Example实例

The following example shows a modify event:以下示例显示了一个modify事件:

{
"_id": { <ResumeToken> },
"operationType": "modify",
"clusterTime": Timestamp({ t: 1654878543, i: 1 }),
"collectionUUID": UUID("47d6baac-eeaa-488b-98ae-893f3abaaf25"),
"wallTime": ISODate("2022-06-10T16:29:03.704Z"),
"ns": {
"db": "test",
"coll": "authors" },
"operationDescription": {
"index": {
"name": "age_1",
"hidden": true
}
},
"stateBeforeChange": {
"collectionOptions": {
"uuid": UUID("47d6baac-eeaa-488b-98ae-893f3abaaf25")
},
"indexOptions": {
"hidden": false
}
}
}