Firebase sort by points depending on date

前端 未结 1 1773
半阙折子戏
半阙折子戏 2020-12-03 09:16

I am trying to add a monthly scoreboard but it seems to be a little bit difficult to me. I don\'t know how to just take a specific value to some list or array. Like Date, on

相关标签:
1条回答
  • 2020-12-03 09:31

    If you want to query date ranges, you should store them in a format that allows querying ranges. For dates that would be either a timestamp or a string that is lexicographically sortable.

    You currently store dates as a dd.MM.yyyy string, which is not lexicographically sortable. I recommend switching to yyyy-MM-dd, so 2019-01-09. That way if you want to get all posts for January, you can do a range query:

    ref.orderByChild("date").startAt("2017-01-01").endAt("2017-01-31")
    

    If you already know that you want monthly leaderboard, I'd recommend changing your database structure to reflect that. So: store the scores by the month that they're in:

    2017-01
      -K34761761238712
        name: "GGGG"
        score: 3
      -K4875731941298a
        name: "AAA"
        score: 1
    

    That way you can get the high scores for January in order with:

    ref.child("2017-01").orderByChild("score").limitToLast(10)
    
    0 讨论(0)
提交回复
热议问题