0

I have a question about firebase sorting.

I have the next database:

{
    "-Ka8xxTgyFB8yYKH50j_addclose" : {
        "number" : 0,
        "point" : 949739,
        "timestamp" : 14824078463440,
        "username" : "Test 16062"
    },
    "-Ka8xzKecpbPr46Kx9gl" : {
        "number" : 0,
        "point" : 1480851,
        "timestamp" : 14842078463441,
        "username" : "Test 13599"
    }
}

I want to display data sorted by point. But i need rows only which created today.

If i filter the rows for timestamp:

return databaseReference
                .child("list")
                .orderByChild("timestamp")
                .endAt(end.getTime());

The endAt is work good. Only todays rows listed. But... Now i need to sort by point.

How can i do it?

There is any idea to change database or sort my list on clientside?

Thanks so much!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
vihkat
  • 895
  • 3
  • 13
  • 28
  • Firebsae DAtabase queries can order by/filter on one property. See http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Jan 13 '17 at 18:43
  • Yes but, if you need to use filter, than first you need to sort it. So: `orderByChild("timestamp").endAt(exampletimestamp).orderByChild("point")` its bad, because 2 orderBy deined on one query. – vihkat Jan 13 '17 at 20:07

1 Answers1

3

You'll need to sort all your data client side as there can only be one orderBy column per query.

If you need to double sort server side you'll have to update your database to have a combined key that would hold both timestamp and point.

Mathew Berg
  • 28,625
  • 11
  • 69
  • 90
  • Yes i want to sort it in client side, but I don't have idea about it. I cant use combinated key with timestamp because this timestamp is {sv.:timestamp} . So in android i use it: `ServerValue.TIMESTAMP`. If i try to concatenate this with point, than the FireBase isn't interpret it. – vihkat Jan 13 '17 at 20:10
  • than value is: {sv. : timestamp}_1231231 – vihkat Jan 13 '17 at 20:11
  • So you have a new question then, how do I order a list client said in android. – Mathew Berg Jan 13 '17 at 20:16
  • I can sort data in android. But this Firebase list is so new for me. I see the adapter with the items. But i can't swap items. – vihkat Jan 13 '17 at 20:18