每天在数据库中增加一个值

Increment value in the database by one every day

我的问题可能非常简单,但我将不胜感激任何帮助,我正在使用 java 和 firebase,并且我在数据库中有一个名为 count == 0 的变量,我需要每天将该值递增1,所以 30 天后变量 count 应该是 count == 30,唯一的麻烦是以编程方式进行增量。

任何建议将不胜感激。

scheduled Cloud Function deployed with the Firebase CLI 将是在 Firebase 中更新数据的正确方法。您可以 运行 一个可以在特定时间(每天或每周)触发的计划函数,并且您可以在函数内更新数据库中的变量。这是来自 firebase 官方文档的示例:

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;
});

在此处阅读文档:https://firebase.google.com/docs/functions/schedule-functions#write_a_scheduled_function