@@ -100,15 +100,31 @@ describe('examples(change-stream):', function() {
100100 // Start Changestream Example 3
101101 const collection = db . collection ( 'inventory' ) ;
102102 const changeStream = collection . watch ( ) ;
103- const change1 = await changeStream . next ( ) ;
104103
105- const resumeAfter = change1 . _id ;
106- changeStream . close ( ) ;
104+ let resumeToken , newChangeStream ;
105+ changeStream . on ( 'change' , next => {
106+ resumeToken = next . _id ;
107+ changeStream . close ( ) ;
107108
108- const newChangeStream = collection . watch ( { resumeAfter } ) ;
109- const change2 = await newChangeStream . next ( ) ;
109+ newChangeStream = collection . watch ( { resumeAfter } ) ;
110+ newChangeStream . on ( 'change' , next => {
111+ // process next document
112+ } ) ;
113+ } ) ;
110114 // End Changestream Example 3
111115
116+ // Start Changestream Example 3 Alternative
117+ const changeStreamIterator = collection . watch ( ) ;
118+ const change1 = await changeStreamIterator . next ( ) ;
119+
120+ const resumeAfter = change1 . _id ;
121+ changeStreamIterator . close ( ) ;
122+
123+ const newChangeStreamIterator = collection . watch ( { resumeAfter } ) ;
124+ const change2 = await newChangeStreamIterator . next ( ) ;
125+ // End Changestream Example 3 Alternative
126+
127+ await newChangeStreamIterator . close ( ) ;
112128 await newChangeStream . close ( ) ;
113129
114130 expect ( change1 ) . to . have . nested . property ( 'fullDocument.a' , 1 ) ;
@@ -128,8 +144,9 @@ describe('examples(change-stream):', function() {
128144 { $match : { 'fullDocument.username' : 'alice' } } ,
129145 { $addFields : { newField : 'this is an added field!' } }
130146 ] ;
147+
131148 const collection = db . collection ( 'inventory' ) ;
132- const changeStream = collection . watch ( { fullDocument : 'updateLookup' } ) ;
149+ const changeStream = collection . watch ( pipeline ) ;
133150 changeStream . on ( 'change' , next => {
134151 // process next document
135152 } ) ;
0 commit comments