What is the correct way to commit multiple batches in a Cloud Function for Firestore? (To ensure the batches run in the background after the function completes execution)
If writing a single batch of <= 500 writes I would have the Cloud Function return the promise returned by batch.commit()
.
However if you need to exceed the 500 write limit, you need to chunk writes into batches of 500 and commit each, as demonstrated in the answer on this SO post. I'm just wondering what the Cloud Function should return to ensure all the batches run smoothly in the background. Currently I'm just returning an array of promises returned by each batch.commit()
, but not sure if that'll cut the mustard.