Drop-in replacement for firebase.firestore.WriteBatch that works around Firestore's 500 batch operations limit.
npm install firestore-multibatch
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));