Complete the code to watch for changes in the 'orders' collection.
const changeStream = db.collection('orders').[1]();
The watch() method starts a change stream to listen for changes in the collection.
Complete the code to filter change events for only 'insert' operations.
const pipeline = [ { $match: { 'operationType': [1] } } ];The operationType field filters events. To watch inserts, use 'insert'.
Fix the error in the code to properly handle change stream events.
changeStream.on('[1]', next => { console.log(next); });
The event name to listen for change notifications is 'change'.
Fill both blanks to create a change stream that watches only 'delete' operations on the 'products' collection.
const pipeline = [ { $match: { 'operationType': [1] } } ]; const changeStream = db.collection([2]).watch(pipeline);To watch deletes on 'products', filter by 'delete' and watch the 'products' collection.
Fill all three blanks to create a change stream that watches 'update' operations and prints the updated fields.
const pipeline = [ { $match: { 'operationType': [1] } } ]; const changeStream = db.collection('users').watch(pipeline); changeStream.on('[2]', change => { console.log(change.updateDescription.[3]); });Filter for 'update' operations, listen on the 'change' event, and access updatedFields to see changed fields.