Skip to content

Commit 1769d63

Browse files
DOCSP-31907 Split Event (mongodb#457)
1 parent 2b26b20 commit 1769d63

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

source/fundamentals/crud/read-operations/change-streams.txt

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,53 @@ An update operation on the collection produces the following output:
137137
...
138138
}
139139

140+
Split Large Change Stream Events
141+
--------------------------------
142+
143+
Starting in MongoDB 7.0, you can use the ``$changeStreamSplitLargeEvent``
144+
aggregation stage to split events that exceed 16 MB into smaller fragments.
145+
The $changeStreamSplitLargeEvent stage returns the fragments sequentially. You can
146+
access the fragments by using a change stream cursor. Each fragment
147+
includes a ``SplitEvent`` object containing the following fields:
148+
149+
.. list-table::
150+
:header-rows: 1
151+
:widths: 35 65
152+
153+
* - Field
154+
- Description
155+
156+
* - ``fragment``
157+
- The index of the fragment, starting at ``1``
158+
159+
* - ``of``
160+
- The total number of fragments that compose the split event
161+
162+
The following example modifies your change stream by using the
163+
``$changeStreamSplitLargeEvent`` aggregation stage to split large events:
164+
165+
.. code-block:: java
166+
167+
ChangeStreamIterable<Document> changeStream = collection.watch(
168+
Arrays.asList(Document.parse("{ $changeStreamSplitLargeEvent: {} }")));
169+
170+
.. note::
171+
172+
You can have only one ``$changeStreamSplitLargeEvent`` stage in your
173+
aggregation pipeline, and it must be the last stage in the pipeline.
174+
175+
You can call the ``getSplitEvent()`` method on your change stream cursor to access
176+
the ``SplitEvent`` as shown in the following example:
177+
178+
.. code-block:: java
179+
180+
MongoChangeStreamCursor<ChangeStreamDocument<Document>> cursor = changeStream.cursor();
181+
SplitEvent event = cursor.tryNext().getSplitEvent();
182+
183+
For more information on the ``$changeStreamSplitLargeEvent`` aggregation stage,
184+
see the :manual:`$changeStreamSplitLargeEvent
185+
</reference/operator/aggregation/changeStreamSplitLargeEvent/>` server documentation.
186+
140187
.. _java-change-stream-configure-pre-post:
141188

142189
Include Pre-images and Post-images
@@ -287,4 +334,4 @@ output:
287334
}
288335

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

0 commit comments

Comments
 (0)