@@ -14,7 +14,7 @@ change stream emits **change event** documents when they occur.
1414The ``watch()`` method optionally takes an **aggregation pipeline** which consists of an array of **aggregation stages**
1515as the first parameter. The aggregation stages filter and transform the change events.
1616
17- In the example below , the ``$match`` stage will match all change event documents with a ``runtime`` value of less than
17+ In the following snippet , the ``$match`` stage matches all change event documents with a ``runtime`` value of less than
181815, filtering all others out.
1919
2020.. code-block:: javascript
@@ -82,23 +82,23 @@ methods presented above:
8282Example
8383-------
8484
85- The following example opens a change stream on the ``movies `` collection in
86- the ``sample_mflix `` database. Let's create a listener function to receive and
85+ The following example opens a change stream on the ``haikus `` collection in
86+ the ``insertDB `` database. Let's create a listener function to receive and
8787print change events that occur on the collection.
8888
8989First, open the change stream on the collection and then define a callback
9090on the change stream using the ``on()`` method. Once set, generate a change
91- event to be emitted by performing a change to the collection.
91+ event by performing a change to the collection.
9292
9393To generate the change event on the collection, let's use ``insertOne()``
9494method to add a new document. Since the ``insertOne()`` may run before the
95- listener function can register, we use a timer, declared with ``setTimeout()``
96- to wait one second before executing the insert.
95+ listener function can register, we use a timer, defined as
96+ ``simulateAsyncPause`` to wait 1 second before executing the insert.
9797
98- We also use a second timer to wait an additional second after the insertion of
99- the document to provide ample time for the change event to be received and
100- the for the callback to complete its execution before closing the
101- ``ChangeStream`` instance using the ``close()`` method.
98+ We also use ``simulateAsyncPause`` after the insertion of the document
99+ to provide ample time for the listener function to receive the change
100+ event and for the callback to complete its execution before
101+ closing the ``ChangeStream`` instance using the ``close()`` method.
102102
103103The timers used in this example are only necessary for this demonstration
104104to make sure there is enough time to register listener and have the
@@ -133,14 +133,12 @@ If you run the preceding example, you should see the following output:
133133 :copyable: false
134134
135135 received a change to the collection: {
136- _id: {
137- _data: '825EC...'
138- },
136+ _id: { _data: '825EC...' },
139137 operationType: 'insert',
140- clusterTime: Timestamp { ... },
141- fullDocument: { _id: 5ec3 ..., test : 'sample movie document' },
142- ns: { db: 'sample_mflix ', coll: 'movies ' },
143- documentKey: { _id: 5ec3 ... },
138+ clusterTime: new Timestamp { ... },
139+ fullDocument: { _id: new ObjectId( ...), title : 'Record of a Shriveled Datum', content: 'No bytes, no problem. Just insert a document, in MongoDB ' },
140+ ns: { db: 'insertDB ', coll: 'haikus ' },
141+ documentKey: { _id: new ObjectId( ...) }
144142 }
145143 closed the change stream
146144
0 commit comments