Skip to content
Merged
Show file tree
Hide file tree
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
93 changes: 46 additions & 47 deletions source/fundamentals/crud/read-operations/change-streams.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,11 @@ classes:
- ``Collection``: To monitor changes in the collection

The following example opens a change stream on the ``restaurants`` collection
and outputs the changes as they occur. Select the
:guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the corresponding
code.
and outputs the changes as they occur. Select the :guilabel:`Synchronous` or
:guilabel:`Asynchronous` tab to see the corresponding code.

.. tabs::

.. tab:: Asynchronous
:tabid: change-stream-async

.. literalinclude:: /includes/code-examples/change-streams/change-streams.cs
:start-after: start-open-change-stream-async
:end-before: end-open-change-stream-async
:language: csharp

.. tab:: Synchronous
:tabid: change-stream-sync

Expand All @@ -87,6 +78,14 @@ code.
:end-before: end-open-change-stream
:language: csharp

.. tab:: Asynchronous
:tabid: change-stream-async

.. literalinclude:: /includes/code-examples/change-streams/change-streams.cs
:start-after: start-open-change-stream-async
:end-before: end-open-change-stream-async
:language: csharp

To begin watching for changes, run the application. Then, in a separate
application or shell, modify the ``restaurants`` collection. Updating a document
that has a ``"name"`` value of ``"Blarney Castle"`` results in the following
Expand Down Expand Up @@ -134,20 +133,12 @@ You can specify the following aggregation stages in the ``pipeline`` parameter:
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
corresponding code.
The following example uses the ``pipeline`` parameter to open a change stream that records
only update operations. Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab
to see the corresponding code.

.. tabs::

.. tab:: Asynchronous
:tabid: change-stream-async

.. literalinclude:: /includes/code-examples/change-streams/change-streams.cs
:start-after: start-change-stream-pipeline-async
:end-before: end-change-stream-pipeline-async
:language: csharp

.. tab:: Synchronous
:tabid: change-stream-sync

Expand All @@ -156,6 +147,14 @@ corresponding code.
:end-before: end-change-stream-pipeline
:language: csharp

.. tab:: Asynchronous
:tabid: change-stream-async

.. literalinclude:: /includes/code-examples/change-streams/change-streams.cs
:start-after: start-change-stream-pipeline-async
:end-before: end-change-stream-pipeline-async
:language: csharp

Split Large Change Events Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -173,14 +172,6 @@ reassemble any event fragments:

.. 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

Expand All @@ -189,6 +180,14 @@ reassemble any event fragments:
:end-before: end-split-change-event-sync
:language: csharp

.. 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

.. note::

We recommend reassembling change event fragments, as shown in the
Expand All @@ -202,6 +201,14 @@ The following code defines these methods:

.. tabs::

.. 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

.. tab:: Asynchronous
:tabid: split-event-helpers-async

Expand All @@ -210,14 +217,6 @@ The following code defines these methods:
: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
Expand Down Expand Up @@ -344,19 +343,11 @@ one of the following values:

The following example opens a change stream on a collection and includes the post-image
of updated documents by specifying the ``FullDocument`` option. Select the
:guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the corresponding
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding
code.

.. tabs::

.. tab:: Asynchronous
:tabid: change-stream-async

.. literalinclude:: /includes/code-examples/change-streams/change-streams.cs
:start-after: start-change-stream-post-image-async
:end-before: end-change-stream-post-image-async
:language: csharp

.. tab:: Synchronous
:tabid: change-stream-sync

Expand All @@ -365,6 +356,14 @@ code.
:end-before: end-change-stream-post-image
:language: csharp

.. tab:: Asynchronous
:tabid: change-stream-async

.. literalinclude:: /includes/code-examples/change-streams/change-streams.cs
:start-after: start-change-stream-post-image-async
:end-before: end-change-stream-post-image-async
:language: csharp

Running the preceding code example and updating a document that has a ``"name"``
value of ``"Blarney Castle"`` results in the following change stream output:

Expand Down
62 changes: 31 additions & 31 deletions source/fundamentals/crud/read-operations/distinct.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ Retrieve Values Across a Collection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following example retrieves the distinct values of the ``borough`` field in
the ``restaurants`` collection. Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous`
the ``restaurants`` collection. Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous`
tab to see the corresponding code.

.. tabs::

.. tab:: Asynchronous
:tabid: distinct-async
.. tab:: Synchronous
:tabid: distinct-sync

.. io-code-block::
:copyable:

.. input:: /includes/fundamentals/code-examples/Distinct.cs
:start-after: start-distinct-async
:end-before: end-distinct-async
:start-after: start-distinct
:end-before: end-distinct
:language: csharp
:dedent:

Expand All @@ -83,15 +83,15 @@ tab to see the corresponding code.
Queens
Staten Island

.. tab:: Synchronous
:tabid: distinct-sync
.. tab:: Asynchronous
:tabid: distinct-async

.. io-code-block::
:copyable:

.. input:: /includes/fundamentals/code-examples/Distinct.cs
:start-after: start-distinct
:end-before: end-distinct
:start-after: start-distinct-async
:end-before: end-distinct-async
:language: csharp
:dedent:

Expand Down Expand Up @@ -119,19 +119,19 @@ For more information about creating a query filter, see the :ref:`csharp-specify

The following example retrieves the distinct values of the ``borough`` field for
all documents that have a ``cuisine`` field value of ``"Italian"``. Select the
:guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the corresponding code.
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code.

.. tabs::
.. tab:: Asynchronous
:tabid: distinct-async

.. tab:: Synchronous
:tabid: distinct-sync

.. io-code-block::
:copyable:

.. input:: /includes/fundamentals/code-examples/Distinct.cs
:start-after: start-distinct-with-query-async
:end-before: end-distinct-with-query-async
:start-after: start-distinct-with-query
:end-before: end-distinct-with-query
:language: csharp
:dedent:

Expand All @@ -143,16 +143,16 @@ all documents that have a ``cuisine`` field value of ``"Italian"``. Select the
Manhattan
Queens
Staten Island

.. tab:: Synchronous
:tabid: distinct-sync
.. tab:: Asynchronous
:tabid: distinct-async

.. io-code-block::
:copyable:

.. input:: /includes/fundamentals/code-examples/Distinct.cs
:start-after: start-distinct-with-query
:end-before: end-distinct-with-query
:start-after: start-distinct-with-query-async
:end-before: end-distinct-with-query-async
:language: csharp
:dedent:

Expand Down Expand Up @@ -196,20 +196,20 @@ all documents that have a ``borough`` field value of ``"Bronx"`` and a
``cuisine`` field value of ``"Pizza"``. Then, it adds a comment to the operation by
providing a ``DistinctOptions`` instance to the ``Distinct()`` method.

Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the
Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the
corresponding code.

.. tabs::
.. tab:: Asynchronous
:tabid: distinct-async

.. tab:: Synchronous
:tabid: distinct-sync

.. io-code-block::
:copyable:

.. input:: /includes/fundamentals/code-examples/Distinct.cs
:start-after: start-distinct-with-comment-async
:end-before: end-distinct-with-comment-async
:start-after: start-distinct-with-comment
:end-before: end-distinct-with-comment
:language: csharp
:dedent:

Expand All @@ -224,16 +224,16 @@ corresponding code.
Amici Pizza And Pasta
Angie'S Cafe Pizza
...

.. tab:: Synchronous
:tabid: distinct-sync
.. tab:: Asynchronous
:tabid: distinct-async

.. io-code-block::
:copyable:

.. input:: /includes/fundamentals/code-examples/Distinct.cs
:start-after: start-distinct-with-comment
:end-before: end-distinct-with-comment
:start-after: start-distinct-with-comment-async
:end-before: end-distinct-with-comment-async
:language: csharp
:dedent:

Expand Down
36 changes: 18 additions & 18 deletions source/fundamentals/crud/read-operations/retrieve.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ results. If no documents match the query filter the methods return ``null``.

.. tabs::

.. tab:: Asynchronous
:tabid: find-one-async
.. tab:: Synchronous
:tabid: find-one-sync

.. code-block:: csharp
:copyable: true

var restaurants = await _restaurantsCollection.Find(filter).FirstOrDefaultAsync();
var restaurants = _restaurantsCollection.Find(filter).FirstOrDefault();

.. tab:: Synchronous
:tabid: find-one-sync
.. tab:: Asynchronous
:tabid: find-one-async

.. code-block:: csharp
:copyable: true

var restaurants = _restaurantsCollection.Find(filter).FirstOrDefault();
var restaurants = await _restaurantsCollection.Find(filter).FirstOrDefaultAsync();

.. tip:: First Document

Expand Down Expand Up @@ -133,21 +133,21 @@ To view a synchronous or asynchronous example, select the corresponding tab.

.. tabs::

.. tab:: Asynchronous
:tabid: find-cursor-async
.. tab:: Synchronous
:tabid: find-cursor-sync

.. code-block:: csharp
:copyable: true

var restaurants = await _restaurantsCollection.Find(filter).ToCursorAsync();
var restaurants = _restaurantsCollection.Find(filter).ToCursor();

.. tab:: Synchronous
:tabid: find-cursor-sync
.. tab:: Asynchronous
:tabid: find-cursor-async

.. code-block:: csharp
:copyable: true

var restaurants = _restaurantsCollection.Find(filter).ToCursor();
var restaurants = await _restaurantsCollection.Find(filter).ToCursorAsync();

If you are returning a small number of documents, or need your results returned
as a ``List`` object, use the ``ToList()`` or ``ToListAsync()`` methods.
Expand All @@ -159,19 +159,19 @@ synchronous or asynchronous example, select the corresponding tab.

.. tabs::

.. tab:: Asynchronous
:tabid: find-list-async
.. tab:: Synchronous
:tabid: find-list-sync

.. code-block:: csharp

var restaurants = await _restaurantsCollection.Find(filter).ToListAsync();
var restaurants = _restaurantsCollection.Find(filter).ToList();

.. tab:: Synchronous
:tabid: find-list-sync
.. tab:: Asynchronous
:tabid: find-list-async

.. code-block:: csharp

var restaurants = _restaurantsCollection.Find(filter).ToList();
var restaurants = await _restaurantsCollection.Find(filter).ToListAsync();

To see a full example of using the ``Find()`` method to find multiple documents,
see :ref:`csharp-retrieve-additional-information`.
Expand Down
Loading
Loading