Introduction
Change streams let you watch for changes in your database in real time without constantly checking it yourself.
const changeStream = collection.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('products').watch(); changeStream.on('change', (change) => { console.log('Change detected:', JSON.stringify(change)); });
orders?watch() on a collection.watch(), while others use incorrect or non-existent methods.users collection?
const changeStream = db.users.watch();
changeStream.on('change', (change) => {
console.log(change.operationType);
});
// Then a new user document is insertedusers collection and logs the operationType.operationType is "insert".const changeStream = db.orders.watch({ $match: { operationType: 'insert' } });
What is the likely cause of the error?[{ $match: { operationType: 'insert' } }].Pass the test and this pattern moves unknown