@@ -71,15 +71,15 @@ Filter the Events
7171~~~~~~~~~~~~~~~~~
7272
7373The ``watch()`` method optionally takes an **aggregation pipeline** which
74- consists of an array of **stages** as the first parameter to filter and
75- transform the change event output as follows:
74+ consists of a list of **stages** as the first parameter, which can be used to
75+ filter and transform the change event output, as follows:
7676
7777.. code-block:: java
7878
79- List<Bson> pipeline = Arrays.asList (
79+ List<Bson> pipeline = List.of (
8080 Aggregates.match(
8181 Filters.in("operationType",
82- Arrays.asList ("insert", "update"))),
82+ List.of ("insert", "update"))),
8383 Aggregates.match(
8484 Filters.lt("fullDocument.runtime", 15)));
8585 ChangeStreamIterable<Document> changeStream = database.watch(pipeline);
@@ -92,38 +92,42 @@ transform the change event output as follows:
9292 by calling the ``fullDocument()`` member method of the ``ChangeStreamIterable``
9393 object with the value ``FullDocument.UPDATE_LOOKUP`` as follows:
9494
95+ .. code-block:: java
96+
97+ ChangeStreamIterable<Document> changeStream = database.watch()
98+ .fullDocument(FullDocument.UPDATE_LOOKUP);
99+
95100Manage the Output
96101~~~~~~~~~~~~~~~~~
97102
98- The ``watch()`` method returns an instance of ``ChangeStreamIterable``, a class
103+ The ``watch()`` method returns an instance of ``ChangeStreamIterable``, an interface
99104that offers several methods to access, organize, and traverse the results.
100- ``ChangeStreamIterable`` also inherits methods from its parent class ,
105+ ``ChangeStreamIterable`` also inherits methods from its parent interface ,
101106``MongoIterable`` which implements the core Java interface ``Iterable``.
102107
103108You can call ``forEach()`` on the ``ChangeStreamIterable`` to handle
104109events as they occur, or you can use the ``iterator()`` method which
105- returns a ``MongoCursor`` instance that you can use to traverse the results.
106-
107- .. important:: forEach() blocks the current thread
110+ returns a ``MongoChangeStreamCursor`` instance that you can use to traverse the results.
108111
109- Calls to ``forEach()`` block the current thread while the
110- corresponding change stream listens for events. If your program
111- needs to continue executing other logic, such as processing requests or
112- responding to user input, consider creating and listening to your
113- change stream in a separate thread.
114-
115- You can call the following methods on the ``MongoCursor`:
112+ You can call the following methods on the ``MongoChangeStreamCursor`:
116113
117114 - ``hasNext()``: checks if there are more results.
118115 - ``next()`` returns the next document in the collection.
119- - ``tryNext()`` immediately returns eitherthe next available element in the
116+ - ``tryNext()`` immediately returns either the next available element in the
120117 change stream or ``null``.
121118
122- Unlike the ``MongoCursor`` returned by other queries, a ``MongoCursor`` associated
123- with a change stream waits until a change event arrives before
124- returning a result from ``next()``. As a result, calls to ``next()``
125- using a change stream's ``MongoCursor`` never throw a
126- ``java.util.NoSuchElementException``.
119+ .. important:: Iterating the Cursor Blocks the Current Thread
120+
121+ Iterating through a cursor using ``forEach()`` or any ``iterator()`` method
122+ blocks the current thread while the corresponding change stream listens for
123+ events. If your program needs to continue executing other logic, such as
124+ processing requests or responding to user input, consider creating and
125+ listening to your change stream in a separate thread.
126+
127+ Unlike the ``MongoCursor`` returned by other queries, a
128+ ``MongoChangeStreamCursor`` associated with a change stream waits until a change
129+ event arrives before returning a result from ``next()``. As a result, calls to
130+ ``next()`` using a change stream's ``MongoChangeStreamCursor`` never throw a ``java.util.NoSuchElementException``.
127131
128132To configure options for processing the documents returned from the change
129133stream, use member methods of the ``ChangeStreamIterable`` object returned
@@ -198,8 +202,7 @@ Full File Example Output
198202
199203The preceding applications will generate the following output:
200204
201- ``Watch.java`` will capture on the ``insert`` and ``update`` operations are
202- printed, since the aggregation pipeline filters out the ``delete`` operation:
205+ ``Watch.java`` will capture only the ``insert`` and ``update`` operations, since the aggregation pipeline filters out the ``delete`` operation:
203206
204207.. code-block::
205208 :copyable: false
@@ -319,7 +322,7 @@ The following example modifies your change stream by using the
319322.. code-block:: java
320323
321324 ChangeStreamIterable<Document> changeStream = collection.watch(
322- Arrays.asList (Document.parse("{ $changeStreamSplitLargeEvent: {} }")));
325+ List.of (Document.parse("{ $changeStreamSplitLargeEvent: {} }")));
323326
324327.. note::
325328
0 commit comments