考虑存储在firebase中的以下JSON格式数据库 -
"root":
{
"survey":
{
"1":
{
"survey_question":"Who is a better player?",
"option1":"Ronaldo",
"option2":"Messi",
"time_posted":7854123265,
"visibility":1
},
"2":
{
"survey_question":"Who is a better singer?",
"option1":"Ed Sheeran",
"option2":"Chris Martin",
"time_posted":9865321245,
"visibility":1
}
}
}
我可以编写Firebase云功能,该功能在创建新调查时触发
但是,我应该如何在0
之后的24小时内更新time_posted
的展示率?
修改:我检查了this page的解决方案并按照说明进行操作 -
index.js
文件中编写了我想要触发并成功部署的函数。https://us-central1-<PROJECT-ID>.cloudfunctions.net/<FUNCTION-NAME>?key=<PROJECT-KEY>
cron作业执行失败,出现以下错误消息 -
Error: Forbidden
Your client does not have permission to get URL /<FUNCTION-NAME>?key=<PROJECT-KEY> from this server.
答案 0 :(得分:0)
使用time_posted
检查Date.now() - time_posted <= 24 * 60 * 60 * 1000
可能更容易进行时间差异(确保它在发布后的一天内)。
或者,在child_added
事件中,您可以执行setTimeout
24小时后回电并更新visibility
标记,但这看起来有点混乱。