Complete the code to watch changes on the 'users' collection.
const changeStream = db.collection('users').[1]();
The watch() method starts a change stream on the collection.
Complete the code to specify the pipeline to filter change events for inserts only.
const pipeline = [ { $match: { 'operationType': [1] } } ];The operationType 'insert' filters events to only new document insertions.
Fix the error in the code to correctly iterate over change events.
for await (const change of changeStream.[1]()) { console.log(change); }
The cursor() method returns an async iterator over the change stream events.
Fill both blanks to create a change stream with a pipeline filtering for deletes and fullDocument lookup.
const changeStream = db.collection('orders').watch([1], { fullDocument: [2] });
The pipeline filters for 'delete' operations, and fullDocument: true returns the full document on change.
Fill all three blanks to handle change events and close the stream on error.
try { for await (const change of changeStream.[1]()) { console.log(change.[2]); } } catch (error) { console.error(error); changeStream.[3](); }
Use cursor() to iterate, access fullDocument for changed data, and close() to stop the stream on error.