1

My app has a for loop that writes data to my Firestore database.

However, right now, when I click my update button, Firestore updates the documents one by one, using transactions. Thus, this results in me having to read every single document before being able to update it, which is extremely inefficient.

Is it possible for batched writes to perform an update feature similar to how transactions do?

For my case, the field I intend to update is a number, thus,

I am wondering if its possible to update the field by adding to it.

 await transaction.update(stockListDocRef, {'Num': outerStockListSnapshot.data['Num'] + Add}); 

1 Answer 1

0

You can use FieldValue.increment(x) to increment a field value in any sort of update operation, including batches.

See also: FieldValue.increment for Cloud Firestore in Flutter

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.