Git Product home page Git Product logo

firestore-big-batch's Introduction

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

firestore-big-batch's People

Contributors

kehlynch avatar lukaszsagol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

firestore-big-batch's Issues

Error: 4 DEADLINE_EXCEEDED: Deadline exceeded

I am trying to use this module inside a cloud function than need to update unknown ammount of documents (but likely over 500 most time).

When using the big batch npm, i still get that error thrown up by firebase :

Error: 4 DEADLINE_EXCEEDED: Deadline exceeded

Any clue of what i should do ?

Thanks

Repository License

Hi, the repository looks good. But I see there is no license attached to the repo.

Repositories without licenses are copyright by default. Therefore, nobody is actually allowed to use this in their projects, nor do I think anyone would dare to contribute ๐Ÿ™ˆ

ChooseALicense is a nice site that can help you pick the right license for this project. I suggest MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.