[英]How to only make data viewable that is within a certain time period in a Firebase Database
I am using Firebase database with an apache cordova (HTML) application to create a chatroom-like project. 我将Firebase数据库与apache cordova(HTML)应用程序配合使用,以创建类似聊天室的项目。 I am trying to change the Firebase rules so that only messages within the past 5 minutes will be appear on the app and modeling an example on their tutorial
我正在尝试更改Firebase规则,以便仅将过去5分钟内的消息显示在应用程序上,并在其教程中为示例建模
I have created this code in my rules section but no data shows up even when the data is entered right away 我已经在规则部分创建了此代码,但是即使立即输入数据也不会显示任何数据
My database data looks like this 我的数据库数据如下所示
What changes do i need to make to my rules code or what kind of formatting do i need to do to my data to make this function work? 为了使此功能正常工作,我需要对规则代码进行哪些更改或需要对数据进行哪种格式设置? Thanks.
谢谢。
The only way to solve this problem that i have found is to edit what is shown in the display in your App and then manually clear the data from your Firebase every now and then. 解决方法我发现的唯一解决此问题的方法是编辑应用程序显示屏中显示的内容,然后不时手动从Firebase中清除数据。 To control what data is accessible in your application simply add if-statement controls to whatever function deals with the 'child_added" function and also create a child node of a timestamp to every parent node you push to the database. Using the timestamp assigned to each node and comparing it to the current timestamp using Date.now() will allow you to control not showing aged-out data.
要控制您的应用程序中可以访问的数据,只需将if语句控件添加到处理“ child_added”函数的函数中,并为您推送到数据库的每个父节点创建一个时间戳子节点。节点并使用Date.now()将其与当前时间戳进行比较,将使您能够控制不显示过期数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.