有办法我可以在firestore文档的特定字段而不是整个文档上设

有办法我可以在firestore文档的特定字段而不是整个文档上设

本文介绍了有没有办法我可以在firestore文档的特定字段而不是整个文档上设置firestore触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用户收藏看起来像这样通知已发送.我无法为整个文档发送 Firestore 触发器,因为令牌字段可以更改.有什么方法可以实现,还是我必须将用户的在线状态存储在单独的集合中

My users collection looks like this i want to set a firestore trigger on the online field of all the users so that whenever user is offline the notifications are not sent to device but are stored in another collection and when the user comes online the notification are sent . I can not sent firestore trigger for the whole document becuase the token field can change . Is there any way to achieve that or do i have to store the online status of user in separate collection

推荐答案

不,这是不可能的.您只能触发整个文档的更改.

No, it's not possible. You can only trigger on changes to the document as a whole.

如果您只希望触发器对特定字段中的更改执行操作,您可以编写函数以仅检查该字段中的更改,而忽略所有其他更改.通过比较提供的 Change 在 onUpdate 触发器中很容易做到这一点对象的 beforeafter 属性,以查看哪些字段实际发生了变化.

If you only want the trigger to take action on changes in a specific field, you can code your function to check for changes in only that field, and ignore all other changes. It's easy to do this in an onUpdate trigger by comparing the provided Change object's before and after properties with each other to see which fields actually changed.

这篇关于有没有办法我可以在firestore文档的特定字段而不是整个文档上设置firestore触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 11:00