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

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

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 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