使用时间戳查询Firebase数据

编程入门 行业动态 更新时间:2024-10-27 18:25:47
本文介绍了使用时间戳查询Firebase数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我当前在Firebase上的数据设计(数据只是事件"参考处的json列表).时间戳记,操作和持续时间字段是固定的,以后可能还会添加更多可选字段.

Here is my current data design on Firebase (data is simply a list of jsons at the "events" reference). The fields timestamp, action, and duration are fixed, and there might be more optional fields added later.

backend-7f34e events -KQ30Lc6lasdfasdfAi1URf action: "Get ready" duration: 100 timestamp: 1472167504389 -KQ30MM8Fgasdf_o10TW action: "Run" duration: 1890 timestamp: 1472167507411

我需要能够从时间戳范围[开始,结束]中检索数据.我需要使用时间戳作为密钥吗?有什么更好的数据结构方式?

I need to be able to retrieve data from a timestamp range [start, end]. Do I need to use timestamp as the key? What would be a better way to structure the data?

推荐答案

结合使用OrderByChild和startAt和endAt

Use OrderByChild combined with startAt and endAt

DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference(); DatabaseReference eventsReference = databaseReference.child("events"); Query query = eventsReference.orderByChild("timestamp").startAt(1472167504389); query.addValueEventListener(new ValueEventListener)..... ....

StartAt以 double 作为参数,因此要相应地构造数据.

StartAt takes double as the argument, so structure your data accordingly.

更多信息- www.firebase/docs /web/api/query/startat.html

更多推荐

使用时间戳查询Firebase数据

本文发布于:2023-10-28 08:51:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536146.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   数据   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!