Complete the code to watch for changes in the 'orders' collection.
const changeStream = db.collection('orders').[1]();
The watch() method opens a change stream to listen for changes in a collection.
Complete the code to handle change events from the change stream.
changeStream.on('[1]', next => { console.log(next); });
The change event fires when a change occurs in the watched collection.
Fix the error in the code to properly start watching changes on the 'users' collection.
const stream = db.collection('users').[1]();
The watch() method does not take an event name as argument; it returns a change stream. The event name is used with on().
Fill both blanks to filter change events for only 'insert' operations.
const pipeline = [ { $match: { 'operationType': [1] } } ];
const stream = db.collection('products').[2](pipeline);The pipeline filters for 'insert' operations, and watch() starts the change stream with that filter.
Fill all three blanks to create a change stream that listens for deletes and logs the document key.
const pipeline = [ { $match: { 'operationType': [1] } } ];
const stream = db.collection('logs').[2](pipeline);
stream.on('[3]', change => { console.log(change.documentKey); });This code watches for 'delete' operations, starts the change stream with watch(), and listens for 'change' events to log the document key.