Skip to content

DOCSP-31907 Split Event #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion source/fundamentals/crud/read-operations/change-streams.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,53 @@ An update operation on the collection produces the following output:
...
}

Split Large Change Stream Events
--------------------------------

Starting in MongoDB 7.0, you can use the ``$changeStreamSplitLargeEvent``
aggregation stage to split events that exceed 16 MB into smaller fragments.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be worth repeating the "should only use when strictly necessary" warning from the server docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in a separate PR: #460

The $changeStreamSplitLargeEvent stage returns the fragments sequentially. You can
access the fragments by using a change stream cursor. Each fragment
includes a ``SplitEvent`` object containing the following fields:

.. list-table::
:header-rows: 1
:widths: 35 65

* - Field
- Description

* - ``fragment``
- The index of the fragment, starting at ``1``

* - ``of``
- The total number of fragments that compose the split event

The following example modifies your change stream by using the
``$changeStreamSplitLargeEvent`` aggregation stage to split large events:

.. code-block:: java

ChangeStreamIterable<Document> changeStream = collection.watch(
Arrays.asList(Document.parse("{ $changeStreamSplitLargeEvent: {} }")));

.. note::

You can have only one ``$changeStreamSplitLargeEvent`` stage in your
aggregation pipeline, and it must be the last stage in the pipeline.

You can call the ``getSplitEvent()`` method on your change stream cursor to access
the ``SplitEvent`` as shown in the following example:

.. code-block:: java

MongoChangeStreamCursor<ChangeStreamDocument<Document>> cursor = changeStream.cursor();
SplitEvent event = cursor.tryNext().getSplitEvent();

For more information on the ``$changeStreamSplitLargeEvent`` aggregation stage,
see the :manual:`$changeStreamSplitLargeEvent
</reference/operator/aggregation/changeStreamSplitLargeEvent/>` server documentation.

.. _java-change-stream-configure-pre-post:

Include Pre-images and Post-images
Expand Down Expand Up @@ -287,4 +334,4 @@ output:
}

For a list of options, see the `FullDocument <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/changestream/FullDocument.html>`__
API documentation.
API documentation.