Here are what I am trying to do with Firebase cloud functions:
Listen to change in one of the documents under 'public_posts' collection.
Tell if the change is in the 'public' field from true to false
If true, delete the document that triggered the function
For steps 1&2, the code is straightforward, but I don't know the syntax for step 3. What would be the way to get the reference of the document that triggered the function? That is, I'd like to know what would be the code in question for the empty line below:
exports.checkPrivate = functions.firestore
.document('public_posts/{postid}').onUpdate((change,context)=>{
const data=change.after.data();
if (data.public===false){
//get the reference of the trigger document and delete it
}
else {
return null;
}
});
Any advice? Thanks!