按日期范围查询Firebase

编程入门 行业动态 更新时间:2024-10-26 12:32:31
本文介绍了按日期范围查询Firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我的firebase数据看起来像这样:

{lambeosaurus:{日期:1420753443,长度:12.5,weight:5000 },stegosaurus:{date:1429053443,length:9,weight:2500 } }

我正在寻找一种使用自定义日期范围来过滤日期的方法。 我已经在网上看到了一些在线查询日期的例子,但时间戳一直是我不能用的关键。

相关部分的文档可以在这里找到: https:/ /www.firebase/docs/web/guide/retrieving-data.html#section-queries

重要的是仍然支持实时更新。我也只想确定符合标准的所有项目的数量。我对每个节点的数据点都不感兴趣。

解决方案

看起来您可以使用 orderBychild ( weight , length ),或者通过子键或属性日期)。如果你使用 startAt()& endAt(),我们可以构建您正在查找的查询:

var startDate = 14200000000; var endDate = 14300000000; ref.orderByChild(date)。startAt(startDate).endAt(endDate) .on(child_added,function(snapshot){ console.log 得到了数据!,快照); });

My firebase data looks something like this:

{ "lambeosaurus": { "date" : 1420753443, "length" : 12.5, "weight": 5000 }, "stegosaurus": { "date" : 1429053443, "length" : 9, "weight" : 2500 } }

I am looking for a way to filter the dates using a custom date range. I've seen some examples online where they have queried for date, but the timestamp has always been the key which isn't possible in my case.

The relevant section is the documentation can be found here: www.firebase/docs/web/guide/retrieving-data.html#section-queries

It's important that real time updating is still supported. I also only want to determine the number of all the items that fit the criterion. I am not interested in the data point for each node.

解决方案

Looks like you can use the orderBychild() method to order by child key or property (i.e. weight, length, or date). And if you chain that using startAt() & endAt(), we can construct the query you're looking for:

var startDate = 14200000000; var endDate = 14300000000; ref.orderByChild("date").startAt(startDate).endAt(endDate) .on("child_added", function(snapshot){ console.log("got the data!", snapshot); });

更多推荐

按日期范围查询Firebase

本文发布于:2023-10-28 23:11:41,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按日   Firebase

发布评论

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

>www.elefans.com

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