0

I want to get snapshot depends on its value if it has for example "red" or "green" colors only. Can i do that in one observe? or should i do two observers

here is example json:

"users" : {
      "EeLIxkOEfhMUlsM8WGnHdgeT8xW2" : {
        "id-854" : { // I want this
          "color" : "red" 
        },
        "id-451" : { // and this
          "color" : "green" 
        },
        "id-153" : {
          "color" : "yellow"
        }
      },

code:

self.ref.child("users").child(handleUser).queryOrdered(byChild: "color").queryEqual(toValue: "red").observe(.childAdded, with: { (snapshot) in

            print(snapshot) // i got red snapshot


        }, withCancel: nil)}

so what's the best way to get two different values, And can i get them with one observe? Thanks!

Sam
  • 137
  • 7
  • There is no way to do an arbitrary OR condition like that in Firebase. Instead you'll need to augment your data structure to have the information you want to look up by (so the color) and then each ID you want to associate with each color. For an example of such a categorization problem, see my answer here: http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Aug 10 '17 at 03:48
  • @FrankvanPuffelen Thank you for answering! – Sam Aug 10 '17 at 13:05

0 Answers0