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?
There are two things that you can do here.
Extensions can be installed multiple times per project, so you can have that one extension installed multiple times if having that would advance your needs.
You can fork and modify the extension and then redeploy it to your project so it suites your needs.
Other than that, if those don't work, I don't believe the extension in its default state will meet your need.