【发布时间】:2021-06-15 15:33:50
【问题描述】:
我需要一个每天自动触发一次的云功能,并在我的“用户”集合中查询“观察”字段为真并将所有这些字段更新为假。在部署我的函数时,我在终端中收到“13:26 错误解析错误:意外的令牌 MyFirstRef”这个错误。 我不熟悉js,所以任何人都可以纠正功能。谢谢。
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const { snapshotConstructor } = require("firebase-functions/lib/providers/firestore");
admin.initializeApp();
exports.changeWatched = functions.pubsub.schedule("every 24 hours").onRun((context) => {
const MyFirstRef = admin.firestore().collection("users")
const queryRef = await MyFirstRef.where("watched", "==", true).get().then((snapshot) => {
snapshot.docs.forEach( doc => {
console.log("debug");
const realId = doc.id
const MyRef = await admin.firestore().collection("users").doc(realId)
MyRef.update({watched: false})
})
})
});
【问题讨论】:
标签: javascript node.js firebase google-cloud-firestore google-cloud-functions