我正在寻找Firebase存储和Firebase Firestore的组合/批量调用的最佳实践。 例如:我需要从我的Firestore中删除与Firebase存储中的图像相关的文档。 是否有可能以这样的方式执行此操作:当其中一个操作失败时,整个事务将被还原?
I'm looking for a best practice on combined/batch calls for Firebase Storage and Firebase Firestore. For example: I need to delete a document from my Firestore which is related to an image in Firebase Storage. Is there a possibility to do this in such a way that when one of the actions fails, the whole transaction is being reverted?
最满意答案
没有真正的atomic/transactional方式,但是您可以使用云功能来可靠地实现它。
您可以删除文档,并使用onDelete触发器删除存储中的实际文件。
因此,当您无法删除文档时,文件不会发生任何事情。 如果您成功删除文档,则会触发云端功能以删除图像。
There is no real atomic/transactional way of doing that however you can use cloud functions to achieve it reliably.
You can delete a document, and use onDelete trigger to delete the actual file in the storage.
So when you can't delete the document, nothing will happen to the file. If you succeed to delete the document, cloud function will be triggered to delete the image.
更多推荐
发布评论