Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

308
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda