Jim Hessin Jim Hessin - 1 year ago 128
Swift Question

Swift Firebase query by child of child

This is a copy of the question here: Querying in Firebase by child of child

There are two answers which are identical but neither of them actually work. I would simply respond to the answers but I don't have the reputation to do that - so I need to ask another question (stackOverflow failure - I can flood the website with multiples but I can't tell someone their answer doesn't work!?!)

I am working on a Firebase app that uses groups. Each group is structured like this

groups : {
"-KW5C5pS_OsWqS8_SLDy" : {
"key" : "-KW5C5pS_OsWqS8_SLDy",
"name" : "Test",
"users" : {
"uFpUrVFafVgVFsQudTNpOquIJZE2" : true

I would like to be able to query for groups that have the current users uid with either true or false indicating if they have admin rights or not. Right now my query looks like this:

.child("groups").queryOrdered(byChild: "users/" + uid).queryEqual(toValue: writable)

This is identical to what was posted as an answer to the other question and stated over and over that it works - however it returns nothing!

Is this a bug or am I doing something wrong?

Answer Source

Okay - I found my problem. I had set a rule to allow me to read only those groups that I am a member of - however evidently this isn't possible with the current Firebase rules language because you need to be able to read the entire directory in order to query it. I have changed the rules to allow all authenticated users to read all the groups and that solved this issue - though it isn't the ideal security.

It took me so long to figure this out because it wasn't giving me a permission denied error in the log - it just gave me an empty query.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download