简体   繁体   中英

Increment value in the database by one every day

My question might be really simple but i will appreciate any help, am using java and firebase and i have a variable in the database called count == 0, i need to increment this value every day by 1, so after 30 days the variable count should be count == 30, the only trouble is making that increment programmaticaly.

Any suggestions will be highly appreciated.

A scheduled Cloud Function deployed with the Firebase CLI will be the proper way to update your data in firebase. Your can run a scheduled function which can be triggered at a specific time (everyday or week however you want) and you can update your variable in the database inside the function. Here is a sample from firebase official documentation:

exports.scheduledFunctionCrontab = functions.pubsub.schedule('5 11 * * *')
  .timeZone('America/New_York') // Users can choose timezone - default is America/Los_Angeles
  .onRun((context) => {
  console.log('This will be run every day at 11:05 AM Eastern!');
  return null;
});

Read documentation here: https://firebase.google.com/docs/functions/schedule-functions#write_a_scheduled_function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM