update
Event
On this page
Summary
Description
Field | Type | Description | |||
---|---|---|---|---|---|
_id | Document | A BSON object which serves as an identifier for the
change stream event. This value is used as the
The For an example of resuming a change stream by | |||
clusterTime | Timestamp | The timestamp from the oplog entry associated with the event. Change stream event notifications associated with a
multi-document transaction
all have the same On sharded clusters, events with the same To identify events for a single transaction, you can use the
combination of | |||
documentKey | document | Document that contains the For sharded collections, this field also displays the full shard key
for the document. The | |||
fullDocument | document | The document created or modified by a CRUD operation. This field only appears if you configured the change stream with
For more information, see Lookup Full Document for Update Operations. | |||
lsid | document | The identifier for the session associated with the transaction. Only present if the operation is part of a multi-document transaction. | |||
ns | document | The namespace (database and or collection) affected by the event. | |||
ns.coll | string | The name of the collection where the event occurred. | |||
ns.db | string | The name of the database where the event occurred. | |||
operationType | string | The type of operation that the change notification reports. Returns a value of | |||
updateDescription | document | A document describing the fields that were updated or removed by the update operation. | |||
updateDescription. removedFields | array | An array of fields that were removed by the update operation. | |||
updateDescription. truncatedArrays | array | An array of documents which record array truncations performed with pipeline-based updates using one or more of the following stages: If the entire array is replaced, the truncations will be reported under updateDescription.updatedFields. | |||
updateDescription. truncatedArrays. field | string | The name of the truncated field. | |||
updateDescription. truncatedArrays. newSize | integer | The number of elements in the truncated array. | |||
updateDescription. updatedFields | document | A document whose keys correspond to the fields that were modified by the update operation. The value of each field corresponds to the new value of those fields, rather than the operation that resulted in the new value. | |||
txnNumber | NumberLong | Together with the lsid, a number that helps uniquely identify a transction. Only present if the operation is part of a multi-document transaction. |
Example
The following example illustrates an update
event:
{ "_id": { <Resume Token> }, "operationType": "update", "clusterTime": <Timestamp>, "ns": { "db": "engineering", "coll": "users" }, "documentKey": { "_id": ObjectId("58a4eb4a30c75625e00d2820") }, "updateDescription": { "updatedFields": { "email": "alice@10gen.com" }, "removedFields": ["phoneNumber"], "truncatedArrays": [ { "field" : "vacation_time", "newSize" : 36 } ] } }
The following example illustrates an update
event for change streams
opened with the fullDocument : updateLookup
option:
{ "_id": { <Resume Token> }, "operationType": "update", "clusterTime": <Timestamp>, "ns": { "db": "engineering", "coll": "users" }, "documentKey": { "_id": ObjectId("58a4eb4a30c75625e00d2820") }, "updateDescription": { "updatedFields": { "email": "alice@10gen.com" }, "removedFields": ["phoneNumber"], "truncatedArrays": [ { "field" : "vacation_time", "newSize" : 36 } ] }, "fullDocument": { "_id": ObjectId("58a4eb4a30c75625e00d2820"), "name": "Alice", "userName": "alice123", "email": "alice@10gen.com", "team": "replication" } }
The fullDocument
document represents the most current majority-committed
version of the updated document. The fullDocument
document may vary from
the document at the time of the update operation depending on the number of
interleaving majority-committed operations that occur between the update
operation and the document lookup.