【发布时间】:2019-06-25 09:28:36
【问题描述】:
我有一个云函数,可以在 3 个不同的集合中运行 3 个 firestore 查询。每个查询在 then 块内都有一个 foreach 循环,在 foreach 循环之后它在集合中执行更新。代码如下:
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!");
那么如何在所有操作完成后返回响应呢?
【问题讨论】:
-
你对
someCollectionRefX.update(....)做了什么??update()不是CollectionReference的方法,而是DocumentReference或WriteBatch的方法。 -
对不起,我的意思是 docRef,我会改变它
-
好的,让我根据您的更新更新我的答案。
标签: node.js firebase google-cloud-firestore google-cloud-functions