0

I have firebase database with structure enter image description here

Now I want to select only names with given gender and qualities. I wrote code like this

private NameImpl.Gender mGender;
private String[] mQualities;

...

public void GetNames()
{
    mRef.orderByChild("Gender").equalTo(mGender.name()).addValueEventListener(new ValueEventListener()
     {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            getData(dataSnapshot);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
     });
}

But I can't understand how to add here requirement that Qualities string in database must contain all words from mQualities.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Andrey Nekrasov
  • 456
  • 2
  • 12
  • Check **[this](https://stackoverflow.com/questions/48340925/how-to-sort-firebase-records-by-two-fields-android)** out. – Alex Mamo May 15 '18 at 15:18

1 Answers1

1

You can't do this with Firebase Realtime Database without some significant changes to your schema. Realtime Database doesn't have the capability to perform filtering on multiple conditions (some people say "multiple where clauses" in SQL terms). If you want to check for matches on multiple things, you'll have to create a composite field that contains a combination of the things you're looking for. For example, you'll need a string value that has gender and all the qualities concatenated together in predictable fashion, then have clients search for that string.

Firestore allows you to filter on multiple conditions, but you still can't search for sets of objects. You'll still need a special field that concatenates all the qualities together.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441