Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between batch and promises

When I want to do multiple writings, deletes or updates to Cloud Firestore from within Cloud Functions, I normally do this with promises:

var proms = []
proms.push(sometask)
return Promises.all(proms)

However I came across batches: https://firebase.google.com/docs/firestore/manage-data/transactions#batched-writes

I think this would look like this:

var batch = db.batch();
batch.update(sometask)
return batch.commit();

What are the difference between those two?

like image 826
J. Doe Avatar asked Apr 25 '26 14:04

J. Doe


1 Answers

When you do Promise.all on a number of operations, those operations are still sent to the server one by one. Each operation can fail individually, while others succeed.

When you use a batched write (or transaction), your operations are sent to the server in one command. This means that they will either all fail, or all succeed.

like image 107
Frank van Puffelen Avatar answered Apr 27 '26 05:04

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!