0

I would like to get a list where deleteStataus= no and userID= userID

Here is my existing code:

  FirebaseRecyclerOptions<ModelMed> options =
            new FirebaseRecyclerOptions.Builder<ModelMed>()
                    .setQuery(FirebaseDatabase.getInstance().getReference().
                                    child("medicines").orderByChild("userId").
                                    equalTo(mysharedPreferance.getUserID()),
                            ModelMed.class)
                    .build();
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Tanveer Hasan
  • 247
  • 2
  • 9

1 Answers1

1

I would like to get a list where deleteStataus= no and userID= userID

What you are looking for is not currently supported. Firebase Realtime Database does not support queries on multiple properties, only supports queries on a single child property. So it can be one (deleteStataus= no) or the other (userId= userId), but not both.

There is however a workaround, in which you can create an extra field to keep the values of both fields. So your schema should look like this:

db
|
--- medicines
      |
      --- Calsin864247
           |
           --- deleteStataus: "no"
           |
           --- userId: "fahar@gmail"
           |
           --- deleteStataus_userId: "no_fahar@gmail"
           |
           --- //other fields.

As you can see, the deleteStataus_userId field combines the values that you want to filter on.

Different than the Firebase Realtime Database, Cloud Firestore allows compound queries. This means that a query such as the one below is allowed without the need of creating a combined property:

medicinesRef.whereEqualTo("deleteStataus", "no").whereEqualTo("userId", "fahar@gmail");
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193