@@ -9,9 +9,13 @@ Watch for Changes
9
9
You can keep track of changes to data in MongoDB, such as changes to a
10
10
collection, database, or deployment, by opening a **change stream**. A change
11
11
stream allows applications to watch for changes to data and react to them.
12
- The change stream returns **change event** documents when changes occur.
13
- You can open a change stream by calling the ``watch()`` method on
14
- a ``MongoCollection``, ``MongoDatabase``, or ``MongoClient`` object:
12
+
13
+ The change stream returns **change event** documents when changes occur. A
14
+ change event contains information about the updated data.
15
+
16
+ Open a change stream by calling the ``watch()`` method on a
17
+ ``MongoCollection``, ``MongoDatabase``, or ``MongoClient`` object as shown in
18
+ the following code example:
15
19
16
20
.. code-block:: java
17
21
@@ -134,27 +138,29 @@ pipeline filters out the ``delete`` operation:
134
138
135
139
Received a change to the collection: ChangeStreamDocument{
136
140
operationType=OperationType{value='insert'},
137
- resumeToken={"_data": "825EC ..."},
141
+ resumeToken={"_data": "825E ..."},
138
142
namespace=sample_mflix.movies,
139
143
destinationNamespace=null,
140
144
fullDocument=Document{{_id=5ec3..., test=sample movie document}},
141
145
documentKey={"_id": {"$oid": "5ec3..."}},
142
146
clusterTime=Timestamp{...},
143
147
updateDescription=null,
144
148
txnNumber=null,
145
- lsid=null
149
+ lsid=null,
150
+ wallTime=BsonDateTime{value=1657...}
146
151
}
147
152
Received a change to the collection: ChangeStreamDocument{
148
153
operationType=OperationType{value='update'},
149
- resumeToken={"_data": "825EC ..."},
154
+ resumeToken={"_data": "825E ..."},
150
155
namespace=sample_mflix.movies,
151
156
destinationNamespace=null,
152
157
fullDocument=Document{{_id=5ec3..., test=sample movie document, field2=sample movie document update}},
153
158
documentKey={"_id": {"$oid": "5ec3..."}},
154
159
clusterTime=Timestamp{...},
155
160
updateDescription=UpdateDescription{removedFields=[], updatedFields={"field2": "sample movie document update"}},
156
161
txnNumber=null,
157
- lsid=null
162
+ lsid=null,
163
+ wallTime=BsonDateTime{value=1657...}
158
164
}
159
165
160
166
You should also see output from the ``WatchCompanion`` application that
0 commit comments