June 2018
Beginner to intermediate
394 pages
9h 2m
English
If you want to listen to all kinds of events occurring in Firestore and trigger a function, we can make use of the onWrite method with a wildcard ID:
exports.modifyUser = functions.firestore .document('users/{userID}') .onWrite(event => { var document = event.data.data();// Update or delete the data var oldDocument = event.data.previous.data(); // perform desired operations ... });
Using event.data, we can read the data and perform the desired action in functions. If you want to write the data with the reference of event.data.ref, we can achieve that. If you want to monitor a complex document structure, you can do it with the help of wildcard values, as shown here:
exports.useMultipleWildcards = functions.firestore ...
Read now
Unlock full access