-
Notifications
You must be signed in to change notification settings - Fork 24
DOCSP-34008: Split large change events #374
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
Show all changes
13 commits
Select commit
Hold shift + click to select a range
811ec32
DOCSP-34008: Split large change events
norareidy a9c6e48
fixes
norareidy 9904225
edits
norareidy b840209
fixes to async code
norareidy 88dcab3
fixes to sync code
norareidy 2cdf355
wording
norareidy 78209e3
admonition
norareidy 7b6e0c7
small fix
norareidy db64098
MM feedback
norareidy 5764b75
FP feedback
norareidy 949557d
tech feedback
norareidy a1666a0
edits
norareidy 9a03ab7
final tech feedback
norareidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,7 @@ for only specified change events. Create the pipeline by using the | |
You can specify the following aggregation stages in the ``pipeline`` parameter: | ||
|
||
- ``$addFields`` | ||
- ``$changeStreamSplitLargeEvent`` | ||
- ``$match`` | ||
- ``$project`` | ||
- ``$replaceRoot`` | ||
|
@@ -119,9 +120,19 @@ You can specify the following aggregation stages in the ``pipeline`` parameter: | |
- ``$set`` | ||
- ``$unset`` | ||
|
||
To learn how to build an aggregation pipeline by using the | ||
``PipelineDefinitionBuilder`` class, see :ref:`csharp-builders-aggregation` in | ||
the Operations with Builders guide. | ||
.. tip:: | ||
|
||
To learn how to build an aggregation pipeline by using the | ||
``PipelineDefinitionBuilder`` class, see :ref:`csharp-builders-aggregation` in | ||
the Operations with Builders guide. | ||
|
||
To learn more about modifying your change stream output, see the | ||
:manual:`Modify Change Stream Output | ||
</changeStreams/#modify-change-stream-output>` section in the {+mdb-server+} | ||
manual. | ||
|
||
Monitor Update Events Example | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The following example uses the ``pipeline`` parameter to open a change stream | ||
that records only update operations. Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the | ||
|
@@ -145,10 +156,73 @@ corresponding code. | |
:end-before: end-change-stream-pipeline | ||
:language: csharp | ||
|
||
To learn more about modifying your change stream output, see the | ||
:manual:`Modify Change Stream Output | ||
</changeStreams/#modify-change-stream-output>` section in the {+mdb-server+} | ||
manual. | ||
Split Large Change Events Example | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
If your application generates change events that exceed 16 MB in size, the | ||
server returns a ``BSONObjectTooLarge`` error. To avoid this error, you can use | ||
the ``$changeStreamSplitLargeEvent`` pipeline stage to split the events | ||
into smaller fragments. The {+driver-short+} aggregation API includes the | ||
``ChangeStreamSplitLargeEvent()`` method, which you can use to add the | ||
``$changeStreamSplitLargeEvent`` stage to the change stream pipeline. | ||
|
||
This example instructs the driver to watch for changes and split | ||
change events that exceed the 16 MB limit. The code prints the | ||
change document for each event and calls helper methods to | ||
reassemble any event fragments: | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably should mention that fragments reassembling is optional (but probably needed), and the split events can be watched as usual events as they arrive. |
||
.. tabs:: | ||
|
||
.. tab:: Asynchronous | ||
:tabid: change-stream-split-async | ||
|
||
.. literalinclude:: /includes/code-examples/change-streams/change-streams.cs | ||
:start-after: start-split-change-event-async | ||
:end-before: end-split-change-event-async | ||
:language: csharp | ||
|
||
.. tab:: Synchronous | ||
:tabid: change-stream-split-sync | ||
|
||
.. literalinclude:: /includes/code-examples/change-streams/change-streams.cs | ||
:start-after: start-split-change-event-sync | ||
:end-before: end-split-change-event-sync | ||
:language: csharp | ||
|
||
.. note:: | ||
|
||
We recommend reassembling change event fragments, as shown in the | ||
preceding example, but this step is optional. You can use the same | ||
logic to watch both split and complete change events. | ||
|
||
The preceding example uses the ``GetNextChangeStreamEvent()``, | ||
``GetNextChangeStreamEventAsync()``, and ``MergeFragment()`` | ||
methods to reassemble change event fragments into a single change stream document. | ||
The following code defines these methods: | ||
|
||
.. tabs:: | ||
|
||
.. tab:: Asynchronous | ||
:tabid: split-event-helpers-async | ||
|
||
.. literalinclude:: /includes/code-examples/change-streams/change-streams.cs | ||
:start-after: start-split-event-helpers-async | ||
:end-before: end-split-event-helpers-async | ||
:language: csharp | ||
|
||
.. tab:: Synchronous | ||
:tabid: split-event-helpers-sync | ||
|
||
.. literalinclude:: /includes/code-examples/change-streams/change-streams.cs | ||
:start-after: start-split-event-helpers-sync | ||
:end-before: end-split-event-helpers-sync | ||
:language: csharp | ||
|
||
.. tip:: | ||
|
||
To learn more about splitting large change events, see | ||
:manual:`$changeStreamSplitLargeEvent </reference/operator/aggregation/changeStreamSplitLargeEvent/>` | ||
in the {+mdb-server+} manual. | ||
|
||
Modify ``Watch()`` Behavior | ||
--------------------------- | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we talk about the
$changeStreamSplitLargeEvent
, but we do not explicitly say that we have it as a step in the typed aggregation api, calledChangeStreamSplitLargeEvent
. We mention this only in the code at the bottom of this section. I think it would be better to make this clear from the start