我的问题可能非常简单,但我会感谢任何帮助,我正在使用 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
关于java - 数据库中的值每天加一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58420843/