0

I would like to know if firebase can query this scenario: I'm searching for people who has a dog and/or a cat. Result should be that i get user1 and user2

{
  "users": {
    "user1": {
      "pets": {
        "dog": true,
        "cat": true
      }
    },
    "user2": {
      "pets": {
        "rabbit": true,
        "cat": true
      }
    },
    "user3": {
      "pets": {
        "bird": true
      }
    }
  }
}

Solution could be for FireStore or Realtime Database

Alex
  • 50
  • 1
  • 6
  • Neither Firebase [Realtime Database](https://stackoverflow.com/questions/29560088/firebase-equivalent-to-sql-where-in) nor [Cloud Firestore](https://stackoverflow.com/questions/47018212/implementing-or-in-firestore-query-firebase-firestore) can query on multiple values of a property (unless those values are in a range). So there is no equivalent for SQL's `SELECT * FROM users WHERE pets IN ("dog", "cat")`. – Frank van Puffelen Nov 24 '17 at 16:45
  • @FrankvanPuffelen how do i have to model my database, that i can do these query? Any advise? – Alex Nov 24 '17 at 16:53
  • If you check Sam's answer on the Firestore link I provided, an option he proposes is to create a `"has_cat_or_dog"` property. Another alternative is to run a query for each option and merge the results client-side. – Frank van Puffelen Nov 24 '17 at 17:04

0 Answers0