1616
1717package documentation ;
1818
19+ import com .mongodb .client .MongoChangeStreamCursor ;
1920import com .mongodb .client .MongoClient ;
2021import com .mongodb .client .MongoClients ;
2122import com .mongodb .client .MongoCollection ;
@@ -69,7 +70,7 @@ public static void main(final String[] args) {
6970 System .out .println ("1. Initial document from the Change Stream:" );
7071
7172 // Create the change stream cursor.
72- MongoCursor <ChangeStreamDocument <Document >> cursor = collection .watch ().iterator ();
73+ MongoChangeStreamCursor <ChangeStreamDocument <Document >> cursor = collection .watch ().cursor ();
7374
7475 // Insert a test document into the collection.
7576 collection .insertOne (Document .parse ("{username: 'alice123', name: 'Alice'}" ));
@@ -86,7 +87,7 @@ public static void main(final String[] args) {
8687 System .out .println ("2. Document from the Change Stream, with lookup enabled:" );
8788
8889 // Create the change stream cursor.
89- cursor = collection .watch ().fullDocument (FullDocument .UPDATE_LOOKUP ).iterator ();
90+ cursor = collection .watch ().fullDocument (FullDocument .UPDATE_LOOKUP ).cursor ();
9091
9192 // Update the test document.
9293 collection .updateOne (Document .parse ("{username: 'alice123'}" ), Document .parse ("{$set : { email: 'alice@example.com'}}" ));
@@ -117,7 +118,7 @@ public static void main(final String[] args) {
117118 );
118119
119120 // Create the change stream cursor with $match.
120- cursor = collection .watch (pipeline ).fullDocument (FullDocument .UPDATE_LOOKUP ).iterator ();
121+ cursor = collection .watch (pipeline ).fullDocument (FullDocument .UPDATE_LOOKUP ).cursor ();
121122
122123 // Forward to the end of the change stream
123124 next = cursor .tryNext ();
@@ -146,11 +147,11 @@ public static void main(final String[] args) {
146147 System .out .println ("4. Document from the Change Stream including a resume token:" );
147148
148149 // Get the resume token from the last document we saw in the previous change stream cursor.
149- BsonDocument resumeToken = next .getResumeToken ();
150+ BsonDocument resumeToken = cursor .getResumeToken ();
150151 System .out .println (resumeToken );
151152
152153 // Pass the resume token to the resume after function to continue the change stream cursor.
153- cursor = collection .watch ().resumeAfter (resumeToken ).iterator ();
154+ cursor = collection .watch ().resumeAfter (resumeToken ).cursor ();
154155
155156 // Insert a test document.
156157 collection .insertOne (Document .parse ("{test: 'd'}" ));
0 commit comments