/firestore-multibatch

Drop-in replacement for firebase.firestore.WriteBatch that works without batch operations limit.

Primary LanguageJavaScriptApache License 2.0Apache-2.0

firestore-multibatch

NPM version Build Code coverage Dependencies Dev dependencies

Drop-in replacement for firebase.firestore.WriteBatch that works around Firestore's 500 batch operations limit.

Installation

npm install firestore-multibatch

Usage

const firebase = require('firebase');
require('firebase/firestore');
const {MultiBatch} = require('firestore-multibatch');

firebase.initializeApp({/* ... */});

const db = firebase.firestore();
const batch = new MultiBatch(db); // Instead of db.batch()

// Perform batch operations same as with db.batch()
for (let i = 0; i < 1000; i++) {
    batch.set(db.collection('test').doc(), {foo: 'bar'});
}

batch.commit()
    .then(() => console.log('Batch operations committed'))
    .catch(err => console.error(err));