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

120
Views
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 answers
Answer question

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