I need a cloud function that triggers automatically once per day and query in my "users" collection where "watched" field is true and update all of them as false. I get "13:26 error Parsing error: Unexpected token MyFirstRef" this error in my terminal while deploying my function. I am not familiar with js so can anyone please correct function. Thanks.
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})
})
})
});