0

Is there anything that could simplify this?

databaseRef.child("palettes").queryOrdered(byChild: "0").queryEqual(toValue: text).observeSingleEvent(of: .value, with: { (snapshot) in

    print (snapshot)

})

databaseRef.child("palettes").queryOrdered(byChild: "1").queryEqual(toValue: text).observeSingleEvent(of: .value, with: { (snapshot) in

    print (snapshot)

})

databaseRef.child("palettes").queryOrdered(byChild: "2").queryEqual(toValue: text).observeSingleEvent(of: .value, with: { (snapshot) in

    print (snapshot)

})

databaseRef.child("palettes").queryOrdered(byChild: "3").queryEqual(toValue: text).observeSingleEvent(of: .value, with: { (snapshot) in

    print (snapshot)

})

databaseRef.child("palettes").queryOrdered(byChild: "4").queryEqual(toValue: text).observeSingleEvent(of: .value, with: { (snapshot) in

    print (snapshot)

})

I wish to query and search for a similar color hex code and then obtain the entire array along with it so the arrangements of my database have to be as such:

enter image description here

AL.
  • 36,815
  • 10
  • 142
  • 281
Ler Ws
  • 317
  • 5
  • 17
  • 1
    Didn't you ask the same thing yesterday? I told you there that you'll need to change your data structure: http://stackoverflow.com/questions/39756884/firebase-query-hex-codes-contained-within-randomly-generated-keys – Frank van Puffelen Sep 29 '16 at 13:23
  • 1
    For this and future questions: you've included a picture of the JSON tree in your question. Please replace that with the actual JSON as text, which you can easily get by clicking the Export button in your Firebase Database console. Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. – Frank van Puffelen Sep 29 '16 at 13:25
  • 1) Array's are evil and will lead to all kinda of issues. Please use childByAutoId and let Firebase create node keys for you. 2) Please don't post images in your questions, only use text. Images are not searchable and make answering harder as the structure would have to be re-typed. You can export your JSON structure from the Firebase console. 3) This is a duplicate question so voting to close. – Jay Sep 29 '16 at 14:17
  • Alright noted, thanks – Ler Ws Sep 29 '16 at 14:52

1 Answers1

0

Try this:-

 FIRDatabase.database().reference().child("palletes").queryOrderedByKey().queryStarting(atValue: "0").queryEnding(atValue: "5").observeSingleEvent(of: .value, with: {(snap) in

    print(snap)

    })
Dravidian
  • 9,945
  • 3
  • 34
  • 74