问题
I am tracking the read/write cost of my HTTP service layer functions.
Am I correct that Collection/Doc/Collection/Doc chains incur no reads?
reads := 0
bucketDocRef := s.fsClient.Collection("accounts").Doc(accountID).Collection("widgets").Doc(widgetID)
// no cost so far?
Also, what is the cost for a call to .Collections(ctx) ... is it 1 read for each collectionRef returned from iter.GetAll()?
iter := docRef.Collections(ctx)
colRefs, _ := iter.GetAll()
reads += len(colRefs)
Also, what is the cost if the call to iter.GetAll() results in an error?
回答1:
Collection and Document are just builder functions. They don't do anything other than build references to collections and documents. They are not actually performing any queries or reading any data, which means they are effectively "free" from the perspective of Firestore billing.
In your example, you won't be billed anything until you call GetAll, which costs 1 read per document returned, plus whatever egress is required.
来源:https://stackoverflow.com/questions/61640921/what-is-the-read-write-cost-for-firestore-docref-collectionsctx