简体   繁体   English

如何仅使Firebase数据库中特定时间段内的数据可见

[英]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.

相关问题 如何让机器人在一段时间后删除消息 - How to make a bot delete messages after a certain time period 如何让一行代码运行一段时间(javaScript) - How to make a line of code run for a certain period of time (javaScript) 如何在一段时间内仅检测一次滚动/滚轮事件? - How to detect a scroll / wheel event only once in a certain period of time? JavaScript在特定时间段内显示数组元素 - JavaScript display array elements within certain time period Highcharts 如何只将可视数据导出到 csv/xlsx? - Highcharts how to only export viewable data to csv/xlsx? 一段时间后如何使HTML5函数关闭脚本? - How to make a HTML5 function to close a script after a certain period of time? 如果在特定时间段内多次按下Tab键,我如何仅触发一个Tab键 - how can i trigger only one tab key if the tab key is pressed numerous times in a certain time period 如何使用 JavaScript 将元素设置为仅在 Wix 中显示一段时间? - How to set an element to show only for a certain period of time in Wix using JavaScript? 如何一次将数据束推入firebase数据库 - How to push bunch of data at a time into firebase database 如果在一段时间后未修改文档,如何自动打勾 function - How do I make a function tick atomically if the document is not modified after a certain period of time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM