RefirebaseRefirebase

batch

Perform multiple write operations as a single batch.

Overview

The batch method creates a new FirestoreWriteBatch which allows you to group up to 500 write operations (set, update, delete) into a single atomic operation. Batched writes complete only if all operations succeed.

Using a write batch
import { db } from 'refirebase';

const batch = db.firestore.batch();

// Queue multiple writes
batch.set('users', 'user1', { name: 'Alice' });
batch.update('users', 'user2', { status: 'active' });
batch.delete('users', 'user3');

// Commit all operations as a single atomic unit
await batch.commit();
console.log('Batch committed!');

Parameters

This method takes no parameters. It returns a FirestoreWriteBatch instance.

Return value

Returns

FirestoreWriteBatch

An object with methods to set, update, delete, and commit batched operations.