最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting Firebase data of last 24 hours - Stack Overflow

programmeradmin5浏览0评论

I'm trying to get Firebase data of the last 24 hours. Actually I have this query:

var ref = firebase.database().ref().child("datos").child("pedidos").child("nuevos");

How I can do that?

I'm trying to get Firebase data of the last 24 hours. Actually I have this query:

var ref = firebase.database().ref().child("datos").child("pedidos").child("nuevos");

How I can do that?

Share Improve this question edited Jan 19, 2018 at 0:04 Frank van Puffelen 601k85 gold badges890 silver badges860 bronze badges asked Jan 18, 2018 at 21:57 FabricioFabricio 3161 gold badge2 silver badges12 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 10

use orderByChild method on the timestamp child (or what ever you use store the time ), and startAt to get the data only that before 24 hours

let before24Hour = new Date().getTime() - (24 * 3600 * 1000);
firebase.database().ref().child('datos/pedidos/nuevos').orderByChild('time').startAt(before24Hour).on('value' , function(snap){
    console.log(snap.val());
});
发布评论

评论列表(0)

  1. 暂无评论