Is My Function Not Resolving Correctly? Also It Won't Write To Firebase To The Databse. No Errors
I have a cloud function that runs with no errors, however, it won't write to the database after Promise.all I've tested this function in a web browser and the data seems to resolve
Solution 1:
It seems you are trying to use getIndex when it is still not available, take a look into async operations... using async/await you can restructure you code to look something like
exports.scheduledIndexUpdate = functions.pubsub
.schedule("every 30 minutes")
.onRun(async context => {
console.log("This will be run every 30 minutes!");
var newIndex;
var getIndex = await admin.collection("billsIndex")
.doc("GS2019Index")
.get()
.then(doc => doc.exists ? doc.data() : null);
// you have you docs available here
for (let prop of getIndex) {
await admin
.firestore()
.collection("billsMetaData")
.doc(key)
.get()
.then(() => { /..,/ })
// etc
}
await admin.firestore().collection("billsIndex")
.doc("GS2019Index2")
.set({
newIndex
});
return Promise.resolve(/.../)
That way you are forcing your execution to wait until promise are resolved
Post a Comment for "Is My Function Not Resolving Correctly? Also It Won't Write To Firebase To The Databse. No Errors"