I have a query that searches for users based on their age:
self?.ref.child(\"users\").queryOrdered(byChild: \"age\").queryStarting(atValue: \"18\").queryEnding(a
In the data you show there are no nodes with 19
or higher, so the query doesn't match any nodes. In that case the .childAdded
event does not fire.
If you want to detect this condition, you must listen to the .value
event, which does fire even when there are no children. But you'll get a single .value
event for all matching children in this case, so you'll need to loop over the child nodes:
self?.ref.child("users")
.queryOrdered(byChild: "age").queryStarting(atValue: "18")
.queryEnding(atValue: "25")
.observeSingleEvent(of: .value, with: { (snapshot) in
print(snapshot.exists())
for child in snapshot.children {
...
}