I have a document collection called schools for which we have kept fields called createdAt and updatedAt. I'm updating these fields using firestore cloud trigger functions in onCreate and onUpdate triggeres respectively.
The problem I'm facing here is, these field updates will call onUpdate trigger again unnecessarily. For these to handle, I've written an additional function called skipOnUpdateTrigger
const excludeFields = ["createdAt", "UpdatedAt"]
shouldSkipOnUpdateTrigger = function(docDataOld, docDataNew, excludeFields){
for(let i of excludeFields){
if (docDataOld[i] !== docDataNew[i])
return true;
}
return false;
}
Is there a better way I can handle this situation to avoid those extra triggers?