Reputation: 343
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?
Upvotes: 4
Views: 1691
Reputation: 598718
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.
Upvotes: 3