If I'm doing a batch write of multiple documents, can I do a transaction for each batch?
I want to update multiple documents but want to make sure that the update for each document doesn't overwrite any concurrent updates made by other users.
Is this possible?
From the Firebase documentation on transactions and batched writes:
There are two types of atomic operations in Cloud Firestore:
Transactions: a transaction is a set of read and write operations on one or more documents.
Batched Writes: a batched write is a set of write operations on one or more documents.
So if a value you need to write depends on an existing value in a document, use a transaction; otherwise use a batched write. You can't mix and match these.
Since you're talking about multiple users potentially overwriting each other's result, it sounds like you need a transaction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With