Firebase query by date range

后端 未结 1 1610
梦谈多话
梦谈多话 2020-12-08 08:03

My firebase data looks something like this:

{
  \"lambeosaurus\": {
    \"date\" : 1420753443,
    \"length\" : 12.5,
    \"weight\": 5000
  },
  \"stegosaur         


        
相关标签:
1条回答
  • 2020-12-08 08:25

    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);
      });
    
    0 讨论(0)
提交回复
热议问题