T3db0t
T3db0t

Reputation: 3551

How can Firestore be used as a queue?

I've got a Firestore collection with about 40,000 items that need to be processed and stored in a separate collection: a queue, in other words.

Really I just need to be able to read a doc from the collection without specifying the doc's id, i.e. "pop", since it doesn't matter what document it is.

I don't want to use my own index because it could lose synchronization for any number of reasons, and then I'd have no idea what index to start again on (without manually counting up until it works again!). Any ideas?

Upvotes: 5

Views: 3289

Answers (2)

Santi Barbat
Santi Barbat

Reputation: 2295

I just created an open-source package to create a queue system using Firestore and Firebase Cloud Functions.

Check it out

Upvotes: 2

krumholz
krumholz

Reputation: 115

I know this question is a bit old but you'd probably want to use a transaction in this instance.

The sequence of events would be something like the following:

  1. Begin loop
  2. Initiate transaction
  3. Read document from collection A
  4. Write document to collection B
  5. Delete document from collection A
  6. Move to next item

Upvotes: 3

Related Questions