MongoDB — Real-Time Change Streams
Build real-time event-driven applications using MongoDB Change Streams (watch()) and resume tokens.
1Watching Real-Time Database Changes
Node.js Change Stream Listener
const changeStream = collection.watch([
{ $match: { operationType: 'insert' } }
]);
changeStream.on('change', (next) => {
console.log("New document inserted:", next.fullDocument);
});