Implementing data-change monitoring
Have you ever wondered what would it be like if you could add extra behavior, or even receive a notification, whenever there's a data manipulation in your database? I bet that would be great to have a feature, and you would be amazed to know that Firebase Cloud Functions has got you covered!
In this recipe, we're going to integrate the monitoring of changes made to data using Firebase Cloud Functions.
Getting ready
Before you start adding your function's implementation, please make sure that your project is ready for Cloud Functions. To double check, please refer to the Getting started with Cloud Functions recipe for assistance.
How to do it...
- As a general use case, we can monitor any path or data we want using nothing but the
changed()
function, this will return a true value if the data did change. So, let's now learn how we can implement it:
exports.updateStats = functions.database.ref('/path/to/data').onWrite( event => { ...