Skip to content

Commit 5bcaa0d

Browse files
committed
change stream
1 parent d8aee63 commit 5bcaa0d

File tree

7 files changed

+56
-189
lines changed

7 files changed

+56
-189
lines changed

source/command.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
Run a Command
33
=============
44

5+
.. facet::
6+
:name: genre
7+
:values: reference
8+
9+
.. meta::
10+
:keywords: database, call, admin, administration, meta, backend, configure
11+
:description: Learn about how to run database commands in the {+driver-long+}.
12+
513
.. contents:: On this page
614
:local:
715
:backlinks: none

source/crud/read-operations.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Read Operations
1717
Limit Returned Results </crud/read-operations/limit>
1818
Specify Fields to Return </crud/read-operations/project>
1919
Count Documents </crud/read-operations/count>
20+
Retrieve Distinct Values of a Field </crud/read-operations/distinct>
2021
Geospatial Data </crud/read-operations/geo>
2122
Search Text </crud/read-operations/text>
2223

@@ -27,5 +28,6 @@ Read Operations
2728
- :doc:`/crud/read-operations/limit`
2829
- :doc:`/crud/read-operations/project`
2930
- :doc:`/crud/read-operations/count`
31+
- :doc:`/crud/read-operations/distinct`
3032
- :doc:`/crud/read-operations/geo`
3133
- :doc:`/crud/read-operations/text`

source/crud/read-operations/count.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
Count Documents
66
===============
77

8+
.. facet::
9+
:name: genre
10+
:values: reference
11+
12+
.. meta::
13+
:keywords: count, number, size, collection
14+
:description: Learn about how to count the number of documents in a collection in the {+driver-long+}.
15+
816
.. contents:: On this page
917
:local:
1018
:backlinks: none

source/usage-examples/distinct.txt renamed to source/crud/read-operations/distinct.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@
44
Retrieve Distinct Values of a Field
55
===================================
66

7-
7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. meta::
12+
:keywords: find, distinct, unique, discrete
13+
:description: Learn about how to retrieve the number of distinct values of a field in the {+driver-long+}.
14+
15+
.. contents:: On this page
16+
:local:
17+
:backlinks: none
18+
:depth: 2
19+
:class: singlecol
820

921
You can retrieve a list of distinct values for a field across a
1022
collection by calling the ``distinct()`` method on a ``MongoCollection``

source/logging-monitoring/change-streams.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
Open Change Streams
77
===================
88

9+
.. facet::
10+
:name: genre
11+
:values: reference
12+
913
.. meta::
1014
:keywords: watch, changestream, log, monitor, events
1115
:description: Learn about how to use change streams in the {+driver-long+}.
@@ -73,10 +77,21 @@ transform the change event output as follows:
7377
.. code-block:: java
7478

7579
List<Bson> pipeline = Arrays.asList(
80+
Aggregates.match(
81+
Filters.in("operationType",
82+
Arrays.asList("insert", "update"))),
7683
Aggregates.match(
7784
Filters.lt("fullDocument.runtime", 15)));
7885
ChangeStreamIterable<Document> changeStream = database.watch(pipeline);
7986

87+
.. note::
88+
89+
For update operation change events, change streams only return the modified
90+
fields by default rather than the entire updated document. You can configure
91+
your change stream to also return the most current version of the document
92+
by calling the ``fullDocument()`` member method of the ``ChangeStreamIterable``
93+
object with the value ``FullDocument.UPDATE_LOOKUP`` as follows:
94+
8095
Manage the Output
8196
~~~~~~~~~~~~~~~~~
8297

@@ -89,6 +104,14 @@ You can call ``forEach()`` on the ``ChangeStreamIterable`` to handle
89104
events as they occur, or you can use the ``iterator()`` method which
90105
returns a ``MongoCursor`` instance that you can use to traverse the results.
91106

107+
.. important:: forEach() blocks the current thread
108+
109+
Calls to ``forEach()`` block the current thread as long as 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+
92115
You can call methods on the ``MongoCursor`` such as ``hasNext()`` to check
93116
whether additional results exist, ``next()`` to return the next document
94117
in the collection, or ``tryNext()``, to immediately return either
@@ -135,6 +158,8 @@ An insert operation on the collection produces the following output:
135158
...
136159
}
137160

161+
.. _java-usage-watch:
162+
138163
Watch Example: Full Files
139164
~~~~~~~~~~~~~~~~~~~~~~~~~
140165

source/usage-examples/watch.txt

Lines changed: 0 additions & 188 deletions
This file was deleted.

0 commit comments

Comments
 (0)