Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

305
Views
Call setTimeout at Firebase Cloud Functions onCreate

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are several problems with your code:

  • You should pass the id as a "simple" argument when calling the updateDoc()method.
  • You need to return a Promise or a value in your Cloud Function to indicate to the Cloud Function platform that the Cloud Function has completed. You'll find more details in the doc and in this video series.

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!