最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

firebase - Does a Firestore Precondition count as an extra read? - Stack Overflow

programmeradmin5浏览0评论

Firestore's Update and Delete document methods accept an optional Precondition argument, to check whether the doc exists or its last update time. Does that check count as an extra document read?

I'd like to add precondition functionality for the Set method (using a read inside a Transaction), but that'll involve an extra read, so I wanted to know if there'd be a difference...

I looked up the Firestore documentation, but couldn't find an answer.

Firestore's Update and Delete document methods accept an optional Precondition argument, to check whether the doc exists or its last update time. Does that check count as an extra document read?

I'd like to add precondition functionality for the Set method (using a read inside a Transaction), but that'll involve an extra read, so I wanted to know if there'd be a difference...

I looked up the Firestore documentation, but couldn't find an answer.

Share Improve this question edited Feb 17 at 6:34 Alex Mamo 139k18 gold badges168 silver badges201 bronze badges Recognized by Google Cloud Collective asked Feb 17 at 5:00 BoBch27BoBch27 261 silver badge3 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Regarding the optional Preconditions argument, please note it doesn't really matter how you read a document, as long as you read it, you have to pay a read operation in Firestore. That being said, if you need to know if a document exists in Firestore before updating it, you should read it first and check if it exists. Why such an extra step? It's because if you want to update a non-existing document, the update operation will fail.

So in my opinion the best option that you have is to perform such an operation in a Firestore transaction, in which case the update will not fail due to the missing document. So please use the transaction object in order to achieve that.

For more information, I recommend you check the official documentation:

  • https://firebase.google/docs/firestore/manage-data/transactions#transactions
发布评论

评论列表(0)

  1. 暂无评论