Skip to content

qualdesk/firestore-big-batch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published