Is it possible to use the Firestore Distributed Counter extension to update multiple document fields simultaneously?
I am currently using the extension, similar to the official examples, to increment a single field in a document. Now, I need to handle multiple fields on a single document. My goal is to increment x
when action A happens, y
when action B happens, and z
when either A or B happens. Since these are very high velocity actions, it would be nice to have this done in as few writes as possible.
First, I looked at using two distributed counters – but this would mean two writes to the main document (one for x
/y
and one for z
) and the n
shards for each counter.
Secondly, I looked at using a single counter. Looking at the incrementBy(val:)
method (on the Web client example) it appears that the update dictionary can be extended to include multiple fields. Is this a valid approach? Will the extension's cloud scheduler correctly aggregate multiple fields?