按日期范围查询Firebase [英] Firebase query by date range
问题描述
{
lambeosaurus:{
日期:1420753443,
长度:12.5,
weight:5000
},
stegosaurus:{
date:1429053443,
length:9,
weight:2500
}
}
我正在寻找一种使用自定义日期范围来过滤日期的方法。
我已经在网上看到了一些在线查询日期的例子,但时间戳一直是我不能用的关键。
相关部分的文档可以在这里找到:
https:/ /www.firebase.com/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: https://www.firebase.com/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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!