I have a cloud function that runs 3 firestore queries in 3 different collections. Each query has a foreach loop inside the then block and after the foreach loop it performs an update in a collection. Here is the code:
const someDocRef
const someDocRef2
const someDocRef3
db.collection("someOtherCollection").get().then(results=> {
results.forEach(result=> {
//do some work
})
someDocRef.update(....);
})
db.collection("someOtherCollection2").get().then(results=> {
results.forEach(result=> {
//do some work
})
someDocRef2.update(....);
})
db.collection("someOtherCollection3").get().then(results=> {
results.forEach(result=> {
//do some work
})
someDocRef3.update(....);
})
res.status(200).send("I waited for all the Queries AND the update operations inside the then blocks of queries to finish!");
So how can I return the response after all the operations finish?