@qualdesk/firestore-big-batch
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Firestore Big Batch

Easily work with Firestore Batched Writes that are bigger than currently allowed by Firestore.

Announcement article

Read an article explaining how this library works: The solution to the Firestore batched write limit

Usage

npm install @qualdesk/firestore-big-batch --save

or

yarn add @qualdesk/firestore-big-batch

Example

import * as admin from 'firebase-admin'
import { BigBatch } from '@qualdesk/firestore-big-batch'

const fs = admin.firestore()
const batch = new BigBatch({ firestore: fs }) //

const ids = myListOfIdsThatMightGoOver499

ids.forEach((id) => {
  const ref = fs.collection('documents').doc(id)
  batch.set(ref, { published: true }, { merge: true })
})

await batch.commit()

Warning

This will create multiple Firestore batches if you have more than 499 operations in your BigBatch, which works for simple use cases, but does not give all the benefits of a Firestore batch.

Todo

  • better error handling when batches fail (Promise.all() is not that great)
  • see if we can support runTransaction
  • write tests!

Contributing

PRs are welcome, or you can raise an issue

Package Sidebar

Install

npm i @qualdesk/firestore-big-batch

Weekly Downloads

2,066

Version

0.0.2

License

ISC

Unpacked Size

4.52 kB

Total Files

6

Last publish

Collaborators

  • callum
  • lukaszsagol