0

I am trying to do a nested query for one of my tables, but it ends up returning all the values in the table where date is bigger instead of returning all the values in the table where userId = userId and date is bigger

DatabaseReference tableAttendObject = getDatabaseTableWith(Constants.tableAttendObject);
Query query = tableAttendObject.orderByChild(Constants.AttendObjectUserUUID).equalTo(userId);
query = query.getRef().orderByChild(Constants.AttendObjectEventDate).startAt(date);

 query.addValueEventListener(new ValueEventListener() {
 //return logic 

My data model in the table is like this:

->id->userId
    ->date 
anho
  • 1,705
  • 2
  • 20
  • 38
  • 1
    You can only order/filter on a single property in Firebase Queries. @uguboz's answer show one solution that may work, but also see http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Feb 13 '17 at 21:30

1 Answers1

2

If you already know userID why you are making a query?? Just do this

Query query = tableAttendObject.child(userId)
.orderByChild(Constants.AttendObjectEventDate)
.startAt(date).addValueEventListener(new ValueEventListener() {
....
ugur
  • 3,604
  • 3
  • 26
  • 57
  • this works only in the case the `id = userId` and I have to retrieve only one object ... in my case `id` is a different id and can be several instances of it – anho Feb 14 '17 at 09:10
  • Aha ok. Then change your database schema. Remove user ID from orders. And add order id's to the user's node such as for user 1: { order1id: true; order2id:true etc. } this way you can identify the orders belong to any user – ugur Feb 14 '17 at 11:42