英文:
Is there a way to make admin changes to Firestore without triggering onUpdate Cloud Function
问题
我正在使用Firebase Cloud Functions。有没有办法在不触发onUpdate的情况下更改用户数据?因此,我有一个onUpdate,每当用户更改数据时都会发送给我一封电子邮件,以便我知道发生了什么。但有时我必须发布、取消发布等用户数据,这会触发云函数的电子邮件。有没有办法不触发电子邮件,比如说“如果这是管理员更改,则不发送电子邮件”。
或者,是否有更好的方法来跟踪Firestore中的用户更改?
英文:
Simple question.
I'm using Firebase Cloud Functions. Is there a way to change user data without trigger onUpdate? So i have an onUpdate that sends me an email whenever a user changes data, so that i know what's going on. But there are times when i have to publish, unpublish etc user data and this triggers cloud functions email. Is there a way to not trigger the email, like say "if this is an admin change, then don't send the email".
Or, is there a better way to track user changes to Firestore?
答案1
得分: 1
没有办法不触发电子邮件,比如说“如果这是管理员更改,则不发送电子邮件”。
在这方面没有所谓的“管理员”访问权限,也没有其他内置的方法可以避免在更新匹配文档时运行更新触发器。触发器运行时您只有文档本身的内容可用,所以您唯一的选择是检查内容并决定是否触发器不执行任何操作。这意味着您可以在同一次更新期间在文档中写入一些字段,以表示不应采取任何操作。
另请参阅:
- https://stackoverflow.com/questions/58559367/update-document-attribute-without-triggering-onupdate-with-cloud-functions
- https://stackoverflow.com/questions/59314716/is-there-a-way-to-suppress-firebase-functions-firestore-triggers
- https://stackoverflow.com/questions/69258690/can-i-avoid-triggering-a-google-cloud-function
英文:
> Is there a way to not trigger the email, like say "if this is an admin change, then don't send the email".
There is no such thing as "admin" access in this respect, and there is no other built-in way to avoid running an update trigger when a matching document is updated. The only information you have available when the trigger runs is the contents of the document itself, so your only option is to check the contents and decide from there if the trigger should do nothing. This means you could possibly write some field in the document during the same update to signal that no action should be taken.
See also:
- https://stackoverflow.com/questions/58559367/update-document-attribute-without-triggering-onupdate-with-cloud-functions
- https://stackoverflow.com/questions/59314716/is-there-a-way-to-suppress-firebase-functions-firestore-triggers
- https://stackoverflow.com/questions/69258690/can-i-avoid-triggering-a-google-cloud-function
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论