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

127
Visualizações
Firebase setting value from another key

I have a firebase function that sets two values to zero. Is there a way to set the value of "lastDaily" to whatever the value of "click" is before setting click to 0?

exports.dailyReset = functions.pubsub.schedule("01 0 * * *")
    .timeZone("Europe/London")
    .onRun((context) => {
      dbCon.once("value", function(snapshot) {
        snapshot.forEach(function(child) {
          child.ref.update({
            lastDaily: 0,
            click: 0,
          });
        });
      });
    });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The following should do the trick (untested):

exports.dailyReset = functions.pubsub.schedule("01 0 * * *")
    .timeZone("Europe/London")
    .onRun(async (context) => {
        
        const snapshot = await dbCon.get();
        
        const promises = [];
        
        snapshot.forEach(child => {
            const oldClickValue = child.val().lastDaily;
            promises.push(child.ref.update({
                lastDaily: oldClickValue,
                click: 0,
            }));
        })
        
        return Promise.all(promises);
        
    });

Note that we use Promise.all() in order to return a Promise when all the asynchronous work is complete. For the same reason note that we use the get() method, which returns a Promise.


Another solution, instead of Promise.all(), would be to use the update() method as shown in this documentation section.

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