0

From below query I get the data in order of timestamp

Query Users = FirebaseDatabase.getInstance.getReference.child("Users").orderbychild("timestamp");

Now all children are ordered by time. But how do I filter this query by CurrentUserId?

Query CurrentUser = Users.orderbychild("CurrentUserId");
Dmitriy Popov
  • 2,150
  • 3
  • 25
  • 34
Vora
  • 347
  • 2
  • 15
  • You can't. Instead use firestore. – DHAVAL A. Jul 19 '19 at 10:35
  • my database is within firebase – Vora Jul 19 '19 at 10:38
  • Firebase Database queries can only order/filter on a single property. In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. For example, you could add a property like `"CurrentUserId_timestamp": "uidOfUser_timestampValue"` and order/filter on that. For an example of this and other approaches, see my answer here: https://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Jul 19 '19 at 13:15

1 Answers1

1

Firebase does not support multiple orderbychild method. What you can do is, first fetch records from Firebase with current user id

Query Users = FirebaseDatabase.getInstance.getReference.child("Users").orderbychild("CurrentUserId");

Then do timestamp sorting at client end.

Nik
  • 1,991
  • 2
  • 13
  • 30