0

I'm trying to retrieve all car data where name is golf but i get no results:

This is my query:

ref.child("auto").queryOrdered(byChild: "name").queryEqual(toValue: "golf").observeSingleEvent(of: .value, with: { (snapshot) in

my Firebase structure is:

-auto

--luhrvuuigvuilthuv

---tgrebytfbyuhbyujvyjb
----name:golf
----age: 2
----color: blue

---funjityvniyyuhntyity
----name:golf
----age: 2
----color: blue

Where is the problem? Thnx in advance

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
HaVaNa7
  • 330
  • 1
  • 3
  • 14
  • The Firebase Database queries child nodes of the location. The property you filter on must be at a fixed location under that child. And `luhrvuuigvuilthuv` doesn't have a property `name`, so the query doesn't match anything. It looks like you're trying to implement categories, for which I described a good data model here: http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Feb 18 '17 at 14:34
  • Thnx man, luhrvuuigvuilthuv is the userid and tgrebytfbyuhbyujvyjb and funjityvniyyuhntyity are childbyautoid. name property is under childbyautoid, how can i do? – HaVaNa7 Feb 18 '17 at 14:40
  • You'll need to pull up the `name` into a list of `names`. See my answer to the question I linked in the first comment. – Frank van Puffelen Feb 18 '17 at 14:53
  • so i have to create in firebase another list when a new car is entered? sorry but i'm new to firebase... thnx anyway – HaVaNa7 Feb 18 '17 at 15:09
  • now i modified my node in this way: -auto --sfghsedhsrtr (autoID of the car) ---addedbyuser: sdgergergh ---namecar: golf ---age:2 ---color:blue Now i can make my query i added indexOn namecar the new problem is that when i want to see all the car from a specific user it shows me but in the output i see that it's better that i indexed addedbyuser and this is impossible... should i wrote another node like the foldaway and keep both? – HaVaNa7 Feb 20 '17 at 12:16

0 Answers0