diff --git a/source/change-streams/change-streams.md b/source/change-streams/change-streams.md index 6021d97ec3..d862e9bf2a 100644 --- a/source/change-streams/change-streams.md +++ b/source/change-streams/change-streams.md @@ -227,6 +227,12 @@ class ChangeStreamDocument { */ clusterTime: Timestamp; + /** + * When this operation was committed. + * Only present for events in a transaction and only when the `showExpandedEvents` change stream option is enabled. + */ + commitTimestamp: Optional; + } class UpdateDescription { @@ -1026,6 +1032,8 @@ There should be no backwards compatibility concerns. ## Changelog +- 2026-01-30: Add `commitTimestamp` to `ChangeStreamDocument`. + - 2025-09-08: Clarify resume behavior. - 2025-03-31: Update for expanded field visibility in server 8.2+ diff --git a/source/change-streams/tests/unified/change-streams-commitTimestamp.json b/source/change-streams/tests/unified/change-streams-commitTimestamp.json new file mode 100644 index 0000000000..353aadc3f0 --- /dev/null +++ b/source/change-streams/tests/unified/change-streams-commitTimestamp.json @@ -0,0 +1,119 @@ +{ + "description": "change-streams-commitTimestamp", + "schemaVersion": "1.7", + "runOnRequirements": [ + { + "minServerVersion": "8.2.0", + "topologies": [ + "replicaset", + "sharded" + ], + "serverless": "forbid" + } + ], + "createEntities": [ + { + "client": { + "id": "client0" + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "database0" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "collection0" + } + }, + { + "session": { + "id": "session0", + "client": "client0" + } + } + ], + "initialData": [ + { + "collectionName": "collection0", + "databaseName": "database0", + "documents": [] + } + ], + "tests": [ + { + "description": "when showExpandedEvents is true, commitTimestamp is included for operations in a transaction", + "operations": [ + { + "name": "createChangeStream", + "object": "collection0", + "arguments": { + "pipeline": [], + "showExpandedEvents": true + }, + "saveResultAsEntity": "changeStream0" + }, + { + "name": "startTransaction", + "object": "session0" + }, + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "x": 1 + }, + "session": "session0" + } + }, + { + "name": "commitTransaction", + "object": "session0" + }, + { + "name": "iterateUntilDocumentOrError", + "object": "changeStream0", + "expectResult": { + "operationType": "insert", + "ns": { + "db": "database0", + "coll": "collection0" + }, + "commitTimestamp": { + "$$exists": true + } + } + }, + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "x": 1 + } + } + }, + { + "name": "iterateUntilDocumentOrError", + "object": "changeStream0", + "expectResult": { + "operationType": "insert", + "ns": { + "db": "database0", + "coll": "collection0" + }, + "commitTimestamp": { + "$$exists": false + } + } + } + ] + } + ] +} diff --git a/source/change-streams/tests/unified/change-streams-commitTimestamp.yml b/source/change-streams/tests/unified/change-streams-commitTimestamp.yml new file mode 100644 index 0000000000..f525df519c --- /dev/null +++ b/source/change-streams/tests/unified/change-streams-commitTimestamp.yml @@ -0,0 +1,65 @@ +description: "change-streams-commitTimestamp" +schemaVersion: "1.7" +runOnRequirements: + - minServerVersion: "8.2.0" + topologies: [ replicaset, sharded ] + serverless: forbid + +createEntities: + - client: + id: &client0 client0 + - database: + id: &database0 database0 + client: *client0 + databaseName: *database0 + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: *collection0 + - session: + id: &session0 session0 + client: *client0 + +initialData: + - collectionName: *collection0 + databaseName: *database0 + documents: [] + +tests: + - description: "when showExpandedEvents is true, commitTimestamp is included for operations in a transaction" + operations: + - name: createChangeStream + object: *collection0 + arguments: + pipeline: [] + showExpandedEvents: true + saveResultAsEntity: &changeStream0 changeStream0 + - name: startTransaction + object: *session0 + - name: insertOne + object: *collection0 + arguments: + document: { x: 1 } + session: *session0 + - name: commitTransaction + object: *session0 + - name: iterateUntilDocumentOrError + object: *changeStream0 + expectResult: + operationType: insert + ns: + db: *database0 + coll: *collection0 + commitTimestamp: { $$exists: true } + - name: insertOne + object: *collection0 + arguments: + document: { x: 1 } + - name: iterateUntilDocumentOrError + object: *changeStream0 + expectResult: + operationType: insert + ns: + db: *database0 + coll: *collection0 + commitTimestamp: { $$exists: false } \ No newline at end of file