GoldenJoe
GoldenJoe

Reputation: 8002

Firestore batch write rollback?

Since transactions are limited in Firestore, sometimes you are stuck performing multiple batch writes, or batch writes that are contingent on other network events. In such a case, if one write succeeds and another fails, is there any way to perform a rollback on the batch that was completed?

Upvotes: 3

Views: 1816

Answers (2)

Doug Stevenson
Doug Stevenson

Reputation: 317467

Firestore does not have a rollback option for batch writes (or transactions) that have already succeeded. If you need to undo a batch write, your application will need to remember the changes that were made in a batch and revert them manually.

Upvotes: 3

Rafael Lemos
Rafael Lemos

Reputation: 5829

As you can see on this community post, if a batch write fails, the entire batch is already rolled back and in case of parallel batch runs it occurs a kind of first in - first out situation, where the batch that executes last is the persistent one, if you want to have some logic or persistence validations to prevent this, you should use transactions.

But batches and Transactions have roughly the same limits, other than the fact that batches are the only offline option, so it is possible to build solutions around that with your code.

Hope this helps.

Upvotes: 3

Related Questions