Batch writes
We gather writes in a batch object and ask Firebase to perform (commit) all the writes at once.
The operation is atomic: if one write fails, the others fail as well. This prevents a broken state where only some documents are updated.
A single network request is sent.
Note: the functions are namespaced on batch both for the client SDK and the admin SDK.
batch changes then commit
Collect up to 500 writes in a batch object, and execute them with commit().
In this example, we use update(), but we could also use set() or other methods.
const batch = writeBatch(db)
// const batch = db.batch() // admin SDK
const change = { timezone: "Europe/London" }
batch.update(docRef1, change)
batch.update(docRef2, change)
// ..
// ..
await batch.commit()
other batch operations
batch.set(docRef, data)
batch.set(docRef, change, { merge: true })
batch.update(docRef, change)
batch.delete(docRef)
batch.create(docRef, data) // Admin SDK