-1

I would like to filter companies based on faculties in my Android App. The problem is that I can't find any method to get all "companies" that contain a certain value on the "faculties" array field. I know that there is similar question for web app but after days of trying to implement this I had no luck.

This is my data structure in Firebase written in JSON:

{
      "Companies" : {
        "01" : {
          "day" : "Wtorek",
          "description" : "Super firma",
          "faculties" : [ null, "Informatyka", "Zarządzanie " ],
          "logoLink" : "gs://testowa-baza-59b76.appspot.com/Loga firm/Netcompany.png",
          "name" : "netcompany",
          "standNumber" : "A68"
        },
        "02" : {
          "day" : "Wtorek|Środa",
          "description" : "Słaba firma",
          "faculties" : [ null, "Informatyka", "Budownictwo" ],
          "logoLink" : "gs://testowa-baza-59b76.appspot.com/Loga firm/PWC.png",
          "name" : "pwc",
          "standNumber" : "B78"
        },
        "03" : {
          "day" : "Środa",
          "description" : "Najgorsza firma świata",
          "faculties" : [ null, "Informatyka", "Matematyka" ],
          "logoLink" : "gs://testowa-baza-59b76.appspot.com/Loga firm/Samsung-logo-2015-Nobg.png",
          "name" : "samsung",
          "standNumber" : "C77"
        }
      }
    }
Alex Mamo
  • 112,184
  • 14
  • 139
  • 167
Robson
  • 9
  • 4

1 Answers1

3

You cannot filter in Firebase objects by a value that exists within an array, and in the same time is a child of the same object.

To simply solve this issue, you can use a tehnique which is called In Firebase denormalization, which means that you'll need to duplicate data in order to achieve what you want. For that, I recomend you see this tutorial, Denormalization is normal with the Firebase Database, for a better understanding.

So, the best option in this case would be to create a top level node named faculties and add there all the faculties you need to. Then simply query this node and you're done! That's it!

Alex Mamo
  • 112,184
  • 14
  • 139
  • 167