Ler Ws Ler Ws - 28 days ago 5
Swift Question

Firebase query hex codes contained within randomly generated keys

I would like to query a particular child from the array of color hex codes.

Here's a snapshot of my database structure:

enter image description here

How do I query a particular hex code and obtain the entire array of its parent object?


You cannot query whether a specific value exists in a list. This is one of the many reasons why the Firebase documentation recommends against using arrays in the database.

But in this case (and most cases that I encounter), you may likely don't really need an array. Say that you just care about what colors your user picked. In that case, you can more efficiently store the colors as a set:

        "0x474A39": true
        "0xbA9A7C": true
        "0xDEDEDF": true
        "0x141414": true
        "0x323E35": true