0.0.2 • Published 3 years ago

@qualdesk/firestore-big-batch v0.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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