Skip to content

Commit 6852bdb

Browse files
Edits
1 parent b05951f commit 6852bdb

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

source/fundamentals/crud/read-operations.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Read Operations
1212

1313
/fundamentals/crud/read-operations/retrieve
1414
/fundamentals/crud/read-operations/count
15+
/fundamentals/crud/read-operations/change-streams
1516

1617
- :ref:`csharp-retrieve`
1718
- :ref:`csharp-count-documents`
19+
- :ref:`csharp-change-streams`

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ Modify the Change Stream Output
106106

107107
You can pass the ``pipeline`` parameter to the ``Watch()`` and ``WatchAsync()``
108108
methods to modify the change stream output. This parameter allows you to watch
109-
for only specified change events. Format the parameter as a list of objects that
110-
each represent an aggregation stage.
109+
for only specified change events. Create the pipeline by using the
110+
``EmptyPipelineDefinition`` class, and appending the relevant aggregation stage methods.
111111

112-
You can specify the following stages in the ``pipeline`` parameter:
112+
You can specify the following aggregation stages in the ``pipeline`` parameter:
113113

114114
- ``$addFields``
115115
- ``$match``
@@ -120,6 +120,9 @@ You can specify the following stages in the ``pipeline`` parameter:
120120
- ``$set``
121121
- ``$unset``
122122

123+
To learn how to build an aggregation pipeline by using the
124+
``PipelineDefinitionBuilder`` class, see :ref:`csharp-builders-aggregation`.
125+
123126
The following example uses the ``pipeline`` parameter to open a change stream
124127
that records only update operations. Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the
125128
corresponding code.
@@ -150,7 +153,7 @@ manual.
150153
Modify ``Watch()`` Behavior
151154
---------------------------
152155

153-
The ``Watch()`` and ``WatchAsync`` methods accept optional parameters, which represent
156+
The ``Watch()`` and ``WatchAsync()`` methods accept optional parameters, which represent
154157
options you can use to configure the operation. If you don't specify any
155158
options, the driver does not customize the operation.
156159

@@ -237,23 +240,25 @@ The **pre-image** is the full version of a document *before* a change. To includ
237240
pre-image in the change stream event, set the ``FullDocumentBeforeChange``
238241
parameter to one of the following values:
239242

240-
- ``WhenAvailable``: The change event includes a pre-image of the
241-
modified document for change events only if the pre-image is available.
242-
- ``Required``: The change event includes a pre-image of the
243-
modified document for change events. If the pre-image is not available, the
244-
driver raises an error.
243+
- ``ChangeStreamFullDocumentBeforeChangeOption.WhenAvailable``: The change event
244+
includes a pre-image of the modified document for change events only if the
245+
pre-image is available.
246+
- ``ChangeStreamFullDocumentBeforeChangeOption.ChangeStreamFullDocumentOption.Required``:
247+
The change event includes a pre-image of the modified document for change
248+
events. If the pre-image is not available, the driver raises an error.
245249

246250
The **post-image** is the full version of a document *after* a change. To include the
247251
post-image in the change stream event, set the ``full_document`` parameter to
248252
one of the following values:
249253

250-
- ``UpdateLookup``: The change event includes a copy of the entire changed
251-
document from some time after the change.
252-
- ``WhenAvailable``: The change event includes a post-image of the
253-
modified document for change events only if the post-image is available.
254-
- ``Required``: The change event includes a post-image of the
255-
modified document for change events. If the post-image is not available, the
256-
driver raises an error.
254+
- ``ChangeStreamFullDocumentOption.UpdateLookup``: The change event includes a
255+
copy of the entire changed document from some time after the change.
256+
- ``ChangeStreamFullDocumentOption.WhenAvailable``: The change event includes a
257+
post-image of the modified document for change events only if the post-image
258+
is available.
259+
- ``ChangeStreamFullDocumentOption.Required``: The change event includes a
260+
post-image of the modified document for change events. If the post-image is
261+
not available, the driver raises an error.
257262

258263
The following example opens a change stream on a collection and includes the post-image
259264
of updated documents by specifying the ``FullDocument`` parameter. Select the
@@ -297,4 +302,4 @@ guide, see the following API documentation:
297302
- `Watch() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.Watch.html>`__
298303
- `WatchAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.WatchAsync.html>`__
299304
- `ChangeStreamOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ChangeStreamOptions.html>`__
300-
- `UpdateOne() <{+new-api-root+}MongoDB.Driver/MongoDB.Driver.IMongoCollectionExtensions.UpdateOne.html>`__
305+
- `UpdateOne() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollectionExtensions.UpdateOne.html>`__

source/includes/code-examples/change-streams/change-streams.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
using var cursor = await collection.WatchAsync();
2121
await cursor.ForEachAsync(change =>
2222
{
23-
Console.WriteLine("Received the following type of change: "change.OperationType);
23+
Console.WriteLine("Received the following type of change: " + change.OperationType);
2424
});
2525
// end-open-change-stream-async
2626

0 commit comments

Comments
 (0)