Firebase Firestore Transaction Error: Cannot Modify A Writebatch That Has Been Committed
I am deploying on cloud functions, and getting this error Error: Cannot modify a WriteBatch that has been committed. at WriteBatch.verifyNotCommitted (/user_code/node_modules/fireb
Solution 1:
This was solved by using a for loop, as mentioned by @Renaud Tarnec in the comments.
I think your problem comes form the fact that you are returning several times the
transaction
into theforEach
loop. Also you don't return the transaction when doingtransaction.update(instanceDocRef, { user_size: newUserSize });
. I would kindly suggest that you study into detail the documentation: https://firebase.google.com/docs/firestore/manage-data/transactions and https://firebase.google.com/docs/reference/js/firebase.firestore.Transaction. With theforEach
loop I think that you are not following the constraint: "A transaction consists of any number of get() operations followed by any number of write operations such as set(), update(), or delete(). "
Post a Comment for "Firebase Firestore Transaction Error: Cannot Modify A Writebatch That Has Been Committed"