Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Query Firebase based on Multiple Equal to [duplicate]

I have below firebase structure. From this I need to fetch data based on query where Dstatus=ok and Drmoble=mobile no

enter image description here

so far I have written this which is working for a single value only.How can I combine both

 mReferenceBooks.orderByChild("Drmoble").equalTo(mobile_no).addValueEventListener(new ValueEventListener() {

 @Override
 public void onDataChange(DataSnapshot dataSnapshot) {
like image 566
Mithu Avatar asked Dec 07 '25 05:12

Mithu


1 Answers

In firebase realtime database, their is no AND query, which means you can't do:

mReferenceBooks.orderByChild("Drmoble").equalTo(mobile_no).orderByChild("DStatus").equalTo("ok")

To solve this you can create another field that will contain both the DStatus and the Drmoble, for example:

randomId
     dstatus-drmoble : "01810000-ok"

Then you can use the following query:

mReferenceBooks.orderByChild("dstatus-drmoble").equalTo("01810000-ok").addValueEventListener(new ValueEventListener() {
like image 147
Peter Haddad Avatar answered Dec 08 '25 17:12

Peter Haddad