Skip to content

Commit a36b84c

Browse files
authored
DOCSP-22867: describe ChangeStreamDocument (#406)
* DOCSP-22867: describe changestreamdocument * first pass fixes * DB PR fixes 1
1 parent d1ae4c7 commit a36b84c

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ changes in the connected MongoDB deployment.
6363
Example
6464
~~~~~~~
6565

66-
The following code example shows how to open a change stream and print
67-
change stream events whenever the data in the collection changes:
66+
This example shows how to open a change stream on the
67+
``myColl`` collection and print change stream events as they occur.
68+
69+
The driver stores change stream events in a variable of type
70+
``ChangeStreamIterable``. In the following example, we specify that the
71+
driver should populate the ``ChangeStreamIterable`` object with ``Document``
72+
types. As a result, the driver stores individual change stream events as
73+
``ChangeStreamDocument`` objects.
6874

6975
.. literalinclude:: /includes/fundamentals/code-snippets/change-streams/ChangeStreams.java
7076
:language: java
@@ -81,7 +87,7 @@ following text:
8187
Received a change: ChangeStreamDocument{
8288
operationType='insert',
8389
resumeToken={"_data": "825EC..."},
84-
namespace=myDb.myChangeStreamCollection,
90+
namespace=myDb.myColl,
8591
...
8692
}
8793

source/includes/fundamentals/code-snippets/change-streams/ChangeStreams.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public static void main(String [] args){
4242
// ChangeStreams.allFullDocumentOptions(collection);
4343
// ChangeStreams.aggregationExample(collection);
4444
}
45-
private static void openExample(MongoCollection<Document> collection) {
45+
private static void openExample(MongoDatabase database) {
4646
// begin openChangeStreamExample
47-
// The collection variable references a MongoCollection instance
48-
ChangeStreamIterable<Document> changeStream = collection.watch();
47+
MongoCollection<Document> collection = database.getCollection("myColl");
4948

49+
ChangeStreamIterable<Document> changeStream = collection.watch();
5050
changeStream.forEach(event ->
5151
System.out.println("Received a change: " + event));
5252
// end openChangeStreamExample

0 commit comments

Comments
 (0)