Trying to write more than 500 documents using Firestore Batch. And I'm wondering if all the batch writes get rollbacked automatically if any batch write fails. If not, how can I achieve that, is there any way to overcome the 500 writes limit with Transaction.
const BATCH_CHUNK = 500
const batches = []
for (let i = 0; i < snapshot.docs.length; i += BATCH_CHUNK) {
const batch = db.batch()
snapshot.docs.slice(i, i + BATCH_CHUNK).forEach(doc => {
batch.update(doc.ref, { committed: true })
})
batches.push(batch.commit())
}
await Promise.all(batches)
Batch writes are executed atomically indeed. If one of the writes gets rejected by say security rules, the other writes in that batch are rejected too. So either all writes in a batch are committed, or none of them are.