Skip to content
Merged
77 changes: 70 additions & 7 deletions source/change-streams/change-streams.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Change Streams
:Status: Accepted
:Type: Standards
:Minimum Server Version: 3.6
:Last Modified: 2022-05-17
:Version: 1.15
:Last Modified: 2022-05-19
:Version: 1.16

.. contents::

Expand Down Expand Up @@ -137,7 +137,21 @@ If an aggregate command with a ``$changeStream`` stage completes successfully, t
* MUST NOT err when they encounter a new `operationType`. Unknown `operationType`
* values may be represented by "unknown" or the literal string value.
*/
operationType: "insert" | "update" | "replace" | "delete" | "invalidate" | "drop" | "dropDatabase" | "rename";
operationType: "insert"
| "update"
| "replace"
| "delete"
| "invalidate"
| "drop"
| "dropDatabase"
| "rename"
| "createIndexes"
| "dropIndexes"
| "modify"
| "create"
| "shardCollection"
| "refineCollectionShardKey"
| "reshardCollection";
Comment thread
benjirewis marked this conversation as resolved.

Comment on lines +153 to 155

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refineCollectionShardKey and reshardCollection events are behind a (currently unsupported) feature flag. I included them here for completeness, but notice that there are no spec tests testing for these new events. If there are no objections, I can file a follow up ticket to add tests for these events once they're available.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Sounds like the feature flag won't be supported until 6.1.0. I agree that we should file a follow-up ticket and add tests once the feature flag can be enabled and drivers can actually test.

/**
* Contains two fields: "db" and "coll" containing the database and
Expand All @@ -155,6 +169,16 @@ If an aggregate command with a ``$changeStream`` stage completes successfully, t
*/
to: Optional<Document>;

/**
* Only present for ops of type 'rename', 'create', 'modify', 'createIndexes', 'dropIndexes', 'shardCollection', 'reshardCollection', 'refineCollectionShardKey'.
* Only present when the `showExpandedEvents` change stream option is enabled.
*
* A description of the operation.
*
* @since 6.0.0
*/
operationDescription: Optional<Document>

/**
* Only present for ops of type ‘insert’, ‘update’, ‘replace’, and
* ‘delete’.
Expand All @@ -168,9 +192,6 @@ If an aggregate command with a ``$changeStream`` stage completes successfully, t

/**
* Only present for ops of type ‘update’.
*
* Contains a description of updated and removed fields in this
* operation.
*/
updateDescription: Optional<UpdateDescription>;

Expand Down Expand Up @@ -208,7 +229,29 @@ If an aggregate command with a ``$changeStream`` stage completes successfully, t
* The wall time from the mongod that the change event originated from.
* Populated for server versions 6.0 and above.
*/
wallTime: Optional<Datetime>;
wallTime: Optional<DateTime>;

/**
* The `ui` field from the oplog entry corresponding to the change event.
*
* Only present when the `showExpandedEvents` change stream option is enabled and for the following events
* - 'insert'
* - 'update'
* - 'delete'
* - 'createIndexes'
* - 'dropIndexes'
* - 'modify'
* - 'drop'
* - 'create'
* - 'shardCollection'
* - 'reshardCollection'
* - 'refineCollectionShardKey'
*
* This field is a value of binary subtype 4 (UUID).
*
* @since 6.0.0
*/
collectionUUID: Optional<Binary>;
}

class UpdateDescription {
Expand Down Expand Up @@ -496,6 +539,24 @@ Driver API
* @note this is an aggregation command option
*/
comment: Optional<any>

/**
* Enables the server to send the 'expanded' list of change stream events.
* The list of additional events included with this flag set are
* - createIndexes
* - dropIndexes
* - modify
* - create
* - shardCollection
* - reshardCollection
* - refineCollectionShardKey
*
* This flag is available in server versions greater than 6.0.0. `reshardCollection` and
* `refineCollectionShardKey` events are not available until server version 6.1.0.
*
* @note this is an option of the change stream pipeline stage
*/
showExpandedEvents: Optional<Boolean>
}

**NOTE:** The set of ``ChangeStreamOptions`` may grow over time.
Expand Down Expand Up @@ -1007,3 +1068,5 @@ Changelog
+------------+------------------------------------------------------------+
| 2022-05-17 | Added ``wallTime`` to ``ChangeStreamDocument``. |
+------------+------------------------------------------------------------+
| 2022-05-19 | Support new change stream events with showExpandedEvents. |
+------------+------------------------------------------------------------+
Loading