【发布时间】:2021-08-11 21:19:33
【问题描述】:
以下函数应该从某些文档的字段中接收数据。然后在另一个集合中查询时使用该数据。查询后它应该更新文档。该代码在编辑器中没有给出任何错误,但它不起作用。
export const dailyTaskFunction2 = functions.pubsub
.schedule("0 0 * * *")
.timeZone("Europe/Istanbul")
.onRun(async () => {
const users = await db
.collection("users")
.where("location", "==", "GMT+3")
.get();
const taskPromises = users.docs.map((doc) => {
return db
.collection("tasks")
.where("dailyTasks", "==", true)
.where("completed", "==", true)
.where("userID", "==", doc.get("userID"))
.get();
});
const taskDocs = await Promise.all(taskPromises);
const actionsPromises = taskDocs.map((snapshots) => {
return snapshots.docs.map((snapshot) => {
return db
.collection("tasks")
.doc(snapshot.id)
.set({completed: false}, {merge: true});
});
});
await Promise.all(actionsPromises);
return null;
});
【问题讨论】:
标签: typescript google-cloud-firestore google-cloud-functions