firebase - Firestore文档(重新)创建未触发Firebase“onCreate”功能
问题描述
我有一个由 Firestore 文档创建(onCreate() 触发)触发的 Firebase 函数。
在相同的情况下,我需要在同一个文档上再次运行相同的函数。由于该函数很长,而且我不想复制它,所以我选择以 hacky 方式触发它:
- 将文档复制到临时集合中
- 删除原始文件
- 再次复制具有相同DocumentId的文档,并将副本中的数据放在其原始位置
- 删除副本
整个事情是通过交易完成的——我想一切都是在后台完成的。
由于步骤 3 使用 SET ( Transaction.set() ) 方法。为什么不触发 onCreate() 事件?
任何帮助或替代我的情况将不胜感激。
谢谢
解决方案
Solved it on my own.
For some reason, doing one transaction that deletes the document, then creates it again, the onCreate() event is not triggered.
I ended up splitting the transaction into two parts. Transaction #1 copies the document in a temporary collection then delete the original. Transaction #2 reads the copy, writes the original document in its original collection, with its original DocumentId, and then deletes the temporary copy.
This way, there are a few milliseconds between the delete and create operation of a document, and they are not bundled in the same transaction.
This solved it. Even though I still don't get why the onCreate() event won't trigger by a Document Creation operation that is inside one Transaction.
推荐阅读
- arangodb - ArangoDB AQL:LOWER 不适用于切片的价值?
- java - 不能写字段名,需要一个值
- angular - 我如何强制应用程序询问用户相机权限?
- android - 如何修复android中RxBus中的调用重复方法
- django - 在同一页面中将 CreateView 转换为 Modal
- sql - 从 PostgreSQL 表的列中删除重复值,并为重复的行每列只保留一个值
- node.js - Wso2 apim 存储中的 api 调用“TypeError: failed to fetch”
- spring-boot - spring 集成 kafka 版本 3.x 中是否有任何可用于入站通道适配器的 xml 配置
- azure - 通过现场网关与 IoT Central 进行连接
- javascript - 如何循环数组并执行字段以获取正确匹配的部分?