I am trying to query data in my Firebase database using:
queryEqual(toValue: Any?, childKey: String?)
My database structure:
The two-parameter queryEqualToValue:childKey:
(and its brethren queryStartingAtValue:childKey:
and queryEndingAtValue:childKey:
) are unfortunately some of the most misunderstood methods in the Firebase Database API.
To order by a child and then filter on a value of that child, you have to call queryOrderedByChild().queryEqualToValue()
. So as @ElCaptainV2.0 said:
databaseReference.child("Schools")
.queryOrderedByChild("schoolNameLC")
.queryEqualToValue("test school 1")
You only should use the childKey:
parameter if you also want to start at a specific key in all nodes that have the same matching test school 1
value. This overload is really mostly useful when you're trying to paginate/endless scroll results.