1

I have the following structure in database.

  "globalContestID":  {
        "1181855391902492":
              {
                points: 123456789
                timestamp: 123456789
              },
         "123456742234324":
              {
                points: 1323344234
                timestamp: 122441434
              }  }

I'm trying to get top 10 scores in past week or month etc. I need to get the data between start time and end time and then sort based on points to get top 10.

This returns NULL:

mContestTableName.orderByChild("timestamp")
    .startAt(starttime).endAt(endtime)
    .orderByChild("points")
    .limitToLast(10) { }

If I remove the "points" part, the query returns all data, So data is fine.

What am I doing wrong in the query?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Shrinidhi Rao
  • 263
  • 4
  • 15
  • 1
    I don't think you can `orderByChild` more than once, at least not without overriding the first ones. – OneCricketeer Dec 17 '16 at 03:19
  • You can only have a single `orderBy...` clause in a Firebase Database query. See http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Dec 17 '16 at 04:55
  • orderByChild("timestamp") i don't need that. Its only to get the startAt endAt query. I want to order only by top 10 points. – Shrinidhi Rao Dec 17 '16 at 04:59
  • Okay, then why did you order by it? Or are you just telling me the solution you have? – OneCricketeer Dec 17 '16 at 05:00
  • I want to apply startAt endAt to "timestamp". I do not know how to refer to timestamp values to do that to apply those time frame. Something like mContestTableName. [some reference to child]("timestamp") .startAt(starttime).endAt(endtime) .orderByChild("points") .limitToLast(10) { } – Shrinidhi Rao Dec 17 '16 at 05:05
  • I think Frank here is the better person to ask about that. – OneCricketeer Dec 17 '16 at 05:07
  • @FrankvanPuffelen Any idea how to achieve this – Shrinidhi Rao Dec 17 '16 at 06:54
  • You're trying to filter on date range and then get the top 10 scores. That requires two `orderBy` clauses, which is not supported in Firebase queries. – Frank van Puffelen Dec 17 '16 at 16:17

0 Answers0