5
5
Open Change Streams
6
6
===================
7
7
8
+ .. facet::
9
+ :name: genre
10
+ :values: reference
11
+
12
+ .. meta::
13
+ :keywords: code example, monitoring, aggregation
14
+
8
15
.. contents:: On this page
9
16
:local:
10
17
:backlinks: none
@@ -18,15 +25,16 @@ In this guide, you can learn how to use a **change stream** to monitor
18
25
real-time changes to your database. A change stream is a {+mdb-server+}
19
26
feature that allows your application to subscribe to data changes on a single
20
27
collection, database, or deployment. You can specify a set of aggregation
21
- operators to filter and transform the data your application receives. When
22
- connecting to a MongoDB deployment v6.0 or later, you can configure the
23
- events to include the document data before and after the change.
28
+ operators to filter and transform the data your application receives.
29
+ When connecting to MongoDB v6.0 or later, you can configure the events
30
+ to include the document data before and after the change.
24
31
25
32
Learn how to open and configure your change streams in the following
26
33
sections:
27
34
28
35
- :ref:`<kotlin-change-stream-open>`
29
36
- :ref:`<kotlin-change-stream-aggregation>`
37
+ - :ref:`<kotlin-change-stream-split-large-event>`
30
38
- :ref:`<kotlin-change-stream-configure-pre-post>`
31
39
32
40
.. _kotlin-change-stream-open:
@@ -107,9 +115,8 @@ The following code example shows how you can apply an aggregation pipeline to
107
115
configure your change stream to receive change events for only insert and
108
116
update operations:
109
117
110
-
111
118
.. literalinclude:: /examples/generated/ChangeStreamsTest.snippet.apply-aggregation-operations-to-change-stream.kt
112
- :language: java
119
+ :language: kotlin
113
120
114
121
When the change stream receives an update change event, the preceding code
115
122
example outputs the following text:
@@ -122,6 +129,55 @@ example outputs the following text:
122
129
resumeToken={...},
123
130
...
124
131
132
+ .. _kotlin-change-stream-split-large-event:
133
+
134
+ Split Large Change Stream Events
135
+ --------------------------------
136
+
137
+ When connecting to MongoDB v7.0 or later,
138
+ you can use the ``$changeStreamSplitLargeEvent`` aggregation operator to
139
+ split event documents that exceed 16 MB into smaller fragments.
140
+
141
+ Use the ``$changeStreamSplitLargeEvent`` operator only when you expect
142
+ the change stream events to exceed the document size limit. For
143
+ example, you might use this feature if your application requires full
144
+ document pre-images or post-images.
145
+
146
+ A ``$changeStreamSplitLargeEvent`` aggregation stage returns
147
+ fragments sequentially. You can access the fragments by using a change
148
+ stream cursor. Each fragment document includes a ``splitEvent`` object that
149
+ contains the following fields:
150
+
151
+ .. list-table::
152
+ :header-rows: 1
153
+ :widths: 35 65
154
+
155
+ * - Field
156
+ - Description
157
+
158
+ * - ``fragment``
159
+ - The index of the fragment, starting at ``1``
160
+
161
+ * - ``of``
162
+ - The total number of fragments that compose the split event
163
+
164
+ The following example opens a change stream that includes an aggregation
165
+ pipeline with an ``$changeStreamSplitLargeEvent`` aggregation stage to
166
+ split large events:
167
+
168
+ .. literalinclude:: /examples/generated/ChangeStreamsTest.snippet.split-large-change-stream.kt
169
+ :language: kotlin
170
+
171
+ .. note::
172
+
173
+ You can have only one ``$changeStreamSplitLargeEvent`` stage in your
174
+ aggregation pipeline, and it must be the last stage in the pipeline.
175
+
176
+ To learn more about the ``$changeStreamSplitLargeEvent`` aggregation operator,
177
+ see :manual:`$changeStreamSplitLargeEvent (aggregation)
178
+ </reference/operator/aggregation/changeStreamSplitLargeEvent/>` in the
179
+ Server manual.
180
+
125
181
.. _kotlin-change-stream-configure-pre-post:
126
182
127
183
Include Pre-images and Post-images
0 commit comments