I’m trying to write a scheduled cloud function to reset the value of “status” every day at 12 am. Here’s my firestore structure:
I haven’t really tried coding in javascript before but here’s what I managed with my little knowledge:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const database = admin.firestore();
exports.Rst = functions.pubsub.schedule("0 0 * * *").onRun((context) => {
const alist =
database.collection("SA1XAoC2A7RYRBeAueuBL92TJEk1")
.doc("afternoon").get().then((snapshot)=>snapshot.data["list"]);
for (let i=0; i<alist.length; i++) {
alist[i]["status"]=0;
}
database.collection("SA1XAoC2A7RYRBeAueuBL92TJEk1")
.doc("afternoon").update({
"list": alist,
});
return null;
});
I get the following error when I deploy this function:
Expected Result:
Set the values of all “status” fields to 0.