Introduction
Change streams let you watch for changes in a collection so you can react to them right away without checking the data again and again.
const changeStream = db.collection('yourCollection').watch(pipeline, options);
const changeStream = db.collection('orders').watch();
const pipeline = [ { $match: { operationType: 'insert' } } ]; const changeStream = db.collection('orders').watch(pipeline);
const changeStream = db.collection('orders').watch([], { fullDocument: 'updateLookup' });
const changeStream = db.collection('products').watch(); changeStream.on('change', (change) => { printjson(change); });
change streams on a MongoDB collection?orders in MongoDB?watch().db.orders.watch() correctly starts the change stream on the orders collection.products collection?
const changeStream = db.products.watch();
changeStream.on('change', (change) => {
console.log(change.operationType);
});operationType of that change.operationType is insert.users collection but it throws an error:
const changeStream = db.users.watch({ operationType: 'insert' });
What is the mistake?watch()watch() method expects an array pipeline for filtering, not a direct object.watch method does not accept a filter object directly -> Option Dtasks collection is updated and the status field changes to 'completed'. Which change stream pipeline correctly filters these changes?operationType must be 'update'.updateDescription.updatedFields.status contains changed fields; we check if it equals 'completed'.Pass the test and this pattern moves unknown