0

If I issue this query to my firebase database I can see data

https://movielen4.firebaseio.com/movieLens/movies.json?orderBy="year"&equalTo=1990

Snippet of the JSON:

"586": {
    "genre": ["Children's", "Comedy"],
    "title": "Home Alone ",
    "year": 1990
},
"3773": {
    "genre": ["Comedy"],
    "title": "House Party ",
    "year": 1990
},
"3661": {
    "genre": ["Horror", "Sci-Fi", "Thriller"],
    "title": "Puppet Master II ",
    "year": 1990
},

However If I change the query to

https://movielen4.firebaseio.com/movieLens/movies.json?orderBy="genre"&equalTo="Comedy"

it returns empty results even though as you can see I have the data. My indexes are defined correctly

{
  "rules": {
    "movieLens" : {
      "movies" : {
        ".indexOn": ["genre", "year"]
      },
      "ratings": {
        ".indexOn": ["movieId", "rating", "userid", "timestamp"]
      },
      "users": {
        ".indexOn": ["age", "gender", "occupation", "userId", "zipCode"]
      }
    },
    ".read": true,
    ".write": true        
  }
}

I think I am seeing empty results because Genre is an array. the query succeeds for year because its just a value. Does anyone know how to query when data is inside an array?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
  • This isn't possible with your current data structure. Instead you'll need to invert the data structure to allow the query you want, so: store the movie keys per category. See this question for a brief example: http://stackoverflow.com/questions/25272919/how-to-query-firebase-for-property-with-specific-value-inside-all-children – Frank van Puffelen Feb 16 '16 at 06:42
  • ok. but what if I want to query on category and year? – Knows Not Much Feb 21 '16 at 06:28
  • Then you'd create properties/buckets for that. See http://stackoverflow.com/questions/33336697/nosql-database-design-for-queries-with-multiple-restrictions-firebase – Frank van Puffelen Feb 21 '16 at 07:09

0 Answers0