Reputation: 81
TL;DR - There are conventions/payloads/actions out there, which requires more than 1 batch write to take place.
It occur to me that when im adding a set
operation to a batch
, for an object which is using firestore serverTimstamp
feature, it costs 2 write operations rather than 1.
Could not find any documentation about that.
The problem is, that if you wrap firestore batch with a local counter in your code, to avoid reaching the 500 threshold, you might miss-calculate batch size.
In my example, I am using Golang firestore sdk (but I do believe this issue will be common for all other sdk's because it derives from firestore fundamental mechanism)
batch.Set(ctx, docRef, struct {
LastUpdate time.Time `firestore:"lastUpdate,serverTimestamp"`
}{}, firestore.MergeAll)
--> batch.writes was increased by 2 writes rather than 1
My question is - are any other special firestore values/actions etc' which might also require more than 1 batch write operation to take place? Also do anyone can suggest a workaround for that issue?
Upvotes: 2
Views: 153
Reputation: 598718
So-called field transform operations indeed may require more than one write operation on the server, reducing the capacity of logical write operations you can perform in a batched write or transaction. If I recall correct, you only be charged for one write operation in such cases though.
From the answer I gave before to what is "field transformations" in Firestore?, it seems that the field transform operations that are available are setToServerValue
(the server timestamp you use), increment
, appendMissingElements
, removeAllFromArray
, maximum
and minimum
. I'm not sure if the last two are exposed on any SDK yet.
Upvotes: 2