Reputation: 2609
I'm writing cloud functions for the first time. I've setup the cli and everything, I want my function to trigger whenever there is an operation in my users collection. Here's what my code looks like:
exports.testFn = functions.database.ref("/users/{userId}").onWrite(event => {
console.log("testFn was Triggered!")
console.log(`New write on user's collection: ${event.after.val()}.`)
})
I'm checking logs everytime I write/update something in my users collection there is no console statements or new logs in firebase dashboard. What's wrong? Also, How do i retrive userId
value? Please help!
Upvotes: 0
Views: 51
Reputation: 80944
The code in your question is the onWrite
trigger for realtime database. Since you are using cloud firestore then you can use the onCreate
to read new data added :
exports.dbDelete = functions.firestore.document('/doc/path').onCreate((snap, context) => {
const newData = snap.data(); // data that was created
const authInfo = context.auth;
});
authInfo
will contain Authentication information for the user that triggered the function.
https://firebase.google.com/docs/reference/functions/cloud_functions_.eventcontext
Upvotes: 1