What are Change Streams?
A change stream is a real-time stream of database changes that flows from your database to your application. With change streams, your applications can react—in real time—to data changes in a single collection, a database, or even an entire deployment. For apps that rely on notifications of changing data, change streams are critical.
A few use cases where you might find change streams include:
- Analytics Dashboards - Change streams can provide an audit trail for applications.
- IoT Event Tracking - Change streams can be used to detect and adjust a system to events that internet-enabled devices are tracking - for example, tracking when a device moves outside of a geo-fencing area. A change stream can be filtered to detect only those events that fall outside of this range and trigger an alarm when it happens.
- Real-Time Trading Applications - Change streams can be used to track changes to financial data and react to them in real time.
If you’re using MongoDB 3.6 or later, change streams are already built in, and taking advantage of them is easy.
Let’s look at the major features of MongoDB change streams, some of your options with those streams (such as modifying the output of the stream), and finally dive into code to see how to implement MongoDB change streams with Python and Node.js.
