这是我当前在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数据
发布评论