Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
NodeJs function not working as expected in Firebase Cloud functions

I do have not any familiarity with node/Js but I have 9 functions that I need to use in Firebase cloud functions, I made a scheduled function on a firebase in nodejs but it's not working as expected.

Just for clarification that the document that I want to update is in this hierarchy in firestore:

users (collection) -> abcUser (document) -> others (collection) -> limiter (document)

Below is one of the functions which is running succefuly on google cloud but the document is not getting update/change:

exports.resetLimiter = functions.pubsub
.schedule("*/5 * * * *")
.onRun( async (context) => {
  const snapshot = await db.collection("users").get();
  for (let i = 0; i < snapshot.docs.length; i++) {
    await snapshot[i].query.get.collection("others").doc("limiter")
        .update({
          weeklyFlow: 0.0,
          monthlyFlow: 0.0,
        });
  }
});

Peace!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

update() returns a promise, but you're ignoring them. This causes the function to complete without waiting for the updates to complete. You need to await each one before returning.

Also your function seems to be incorrect in the way it uses the Firestore API. There is no property get on DocumentSnapshot objects. I'll try to rewrite it anyway with await.

      for (var i = 0; i < snapshot.docs.length; i++) {
        await db.collection("others").doc("limiter")
            .update({
              weeklyFlow: 0.0,
              monthlyFlow: 0.0,
            });
      });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda