Couple Firebase Firestore and Firebase Storage cal

2020-04-10 01:59发布

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?

2条回答
淡お忘
2楼-- · 2020-04-10 02:47

None of the Firebase products support such cross-product transactional updates. You'll have to nest the calls during updates, and use code that can handle unexpected data structures during reads.

Also see:

查看更多
The star\"
3楼-- · 2020-04-10 02:50

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.

查看更多
登录 后发表回答