Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transaction within Batch Write Firebase

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?

like image 685
ckingprogramming Avatar asked Sep 12 '25 21:09

ckingprogramming


1 Answers

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.

like image 128
Frank van Puffelen Avatar answered Sep 15 '25 09:09

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!