1+ // start-open-change-stream
2+ // Opens a change stream and prints the changes as they're received
3+ ChangeStreamPublisher <Document > changeStreamPublisher = restaurants .watch ();
4+ Flux .from (changeStreamPublisher )
5+ .doOnNext (change -> System .out .println ("Received change: " + change ))
6+ .blockLast ();
7+ // end-open-change-stream
8+
9+ // start-change-stream-pipeline
10+ // Creates a change stream pipeline
11+ List <Bson > pipeline = Arrays .asList (
12+ Aggregates .match (Filters .eq ("operationType" , "update" ))
13+ );
14+
15+ // Opens a change stream and prints the changes as they're received
16+ ChangeStreamPublisher <Document > changeStreamPublisher = restaurants .watch (pipeline );
17+ Flux .from (changeStreamPublisher )
18+ .doOnNext (change -> System .out .println ("Received change: " + change ))
19+ .blockLast ();
20+ // end-change-stream-pipeline
21+
22+ // start-change-stream-post-image
23+ // Creates a change stream pipeline
24+ List <Bson > pipeline = Arrays .asList (
25+ Aggregates .match (Filters .eq ("operationType" , "update" ))
26+ );
27+
28+ // Opens a change stream and prints the changes as they're received including the full
29+ // document after the update
30+ ChangeStreamPublisher <Document > changeStreamPublisher = restaurants .watch (pipeline )
31+ .fullDocument (FullDocument .UPDATE_LOOKUP );
32+
33+ Flux .from (changeStreamPublisher )
34+ .doOnNext (change -> System .out .println ("Received change: " + change ))
35+ .blockLast ();
36+ // end-change-stream-post-image
0 commit comments