Reputation: 149
I'm using following code in order to call a function with setTimeout, but I'm not really into JS and Firebase Cloud Functions.
However my logs are showing following error: "Function returned undefined, expected Promise or value" "Exception from a finished function: Error: Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string."
This is my code:
function updateDoc(id) {
admin.firestore().collection('Orders').doc(id).update({status: 2}).then(() => {
console.log("Document successfully updated!");
})
.catch((error) => {
console.error("Error updating document: ", error);
});
}
exports.updateField = functions.firestore
.document('/Orders/{id}')
.onCreate((snapshot, context) => {
const id = context.params.id;
setTimeout(updateDoc.bind(id), 30000)
});
Thanks for any kind of help.
Upvotes: 0
Views: 338
Reputation: 83191
There are several problems with your code:
updateDoc()
method.In addition, using setTimeout
in a Cloud Function shall be done with care, see these SO answers. You could probably re-architect your solution in order to avoid the setTimeout
. If you share more info on why you use it, the community may help you.
Upvotes: 2