Complete the code to watch changes on the entire database.
const changeStream = db.[1].watch();To watch changes on the whole database, use db.database.watch().
Complete the code to listen for change events and print them.
changeStream.on('[1]', next => console.log(next));
The event name to listen for changes is 'change'.
Fix the error in the code to start watching changes on a database named 'shopDB'.
const changeStream = client.db('[1]').watch();
The database name must match exactly, including case. Here it is 'shopDB'.
Fill both blanks to filter change events to only 'insert' operations on the database.
const pipeline = [ { $match: { 'operationType': [1] } } ];
const changeStream = db.database.watch(pipeline, { [2]: false });The filter uses 'insert' for operationType, and fullDocument: false disables full document retrieval.
Fill all three blanks to close the change stream properly after use.
async function watchAndClose() {
const changeStream = db.database.watch();
changeStream.on('change', data => console.log(data));
await changeStream.[1]();
console.log('[2] closed');
return [3];
}Use close() to stop the stream, print a message, and return true to indicate success.
