0

I'm a Java, Android and Firebase newbie. I need to query a database by multiple values. I mean: I need to retrieve all data which value is equal to keys stored in a List<String>

Example

{
  "users": {
    "askywalker": {
      "name": "Anakin Skywalker",
    },
    "owkenobi": {
      "name": "Obi-Wan Kenobi",
    },
    "lorgana": {
      "name": "Leila Organa",
    }
  }
}

I need to store both askywlaker and owkenobi in the same Query. How can I do it?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    Firebase Database queries can only select on a single value or a range of values. There is no equivalent to SQL's `SELECT * FROM users WHERE name IN ("askywlaker", "owkenobi")`. See https://stackoverflow.com/questions/29560088/firebase-equivalent-to-sql-where-in – Frank van Puffelen Nov 23 '17 at 15:14
  • @FrankvanPuffelen, does the method `push()` inside a loop that cycles all the keys I'm interested in allows to add leaves to a query? – ChaosMaster84 Nov 27 '17 at 11:50
  • push() writes data and that's not what you are asking about. There are several options for doing this query but as the structure stands it cannot be done directly with Firebase. You could load the nodes in and query/filter in code, you can use something like [ElasticSearch](https://www.elastic.co), you could clarify what kind of data you want out of Firebase - i.e. you're not going to randomly query for data, there needs to be a reason, and that reason determines how your Firebase is structured. – Jay Nov 27 '17 at 20:57

0 Answers0