1

enter image description here

   Query q  = FirebaseDatabase.getInstance().getReference().child("Chats").orderByChild("senderkey")

    .equalTo(FirebaseAuth.getInstance().getCurrentUser().getUid());

In the above code I'm querying using sender = x , what if i want to make this statement senderkey = x and receiverkey = y. In short, how to use AND in firebase ?

because:

I’m displaying the data by querying by senderkey but I don’t want to display the duplicated data again, if the senderkey is repeated i want it to be displayed once

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
Ahmed Imam
  • 1,315
  • 2
  • 19
  • 42

2 Answers2

0

I don't think this is possible. You can't query on multiple children. If you know you want the last message with a specific sender id you can use the limitToLast() function which will eliminate the duplicate concern.

More info on Firebase Database Queries here: https://firebase.google.com/docs/database/admin/retrieve-data

Tristan
  • 1,608
  • 1
  • 20
  • 34
0

These type of queries are not allowed in firebase realtime database You can use firestore for multiple where queries by the way.

If you want to stick with firebase realtime database then you should work on your data model and create combine key to search and perform AND operation.

For example to perform AND operation you need to create a key

"name_createdAt" = "chickungunya_moka"

and then do query for

orderByChild("name_reportedAt").equalsTo(name+"_"+reportedAt);

Nouman Ch
  • 4,023
  • 4
  • 29
  • 42