0

How can I approach a compound query?

I want to get the values where Lamp=id AND AssignedTo=''

So I thought of an approach like this

FirebaseDatabase().reference().child('history').orderByChild('Lamp').equalTo(id).orderByChild('AssignedTo').equalTo('');

But it did not work.

I am using flutter

Kevin M. Mansour
  • 2,915
  • 6
  • 18
  • 35
  • It might be possible if set up an index on the firebase side of things. Not entire sure it will the fix you need though. – Amxela Apr 15 '21 at 17:48
  • you can't query in firebase's real-time database. you have to use firestore. alternative solution https://stackoverflow.com/a/26701282/8822337 – BIS Tech Apr 15 '21 at 17:54
  • 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. In your case that could be `"Lamp_AssignedTo": "idOfLamp_idOfAssignee"`, and you'd then 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 Apr 15 '21 at 21:56

0 Answers0