I'm trying to fetch child snapshot with childKey of unknown parent without changing Data Structure.
I tried to use queryOrderByChildId
with queryEqual(toValue:, childKey:)
But my problem is that the child snapshot is dictionary and I know only the key, not the value.
Is there any way to manipulate the value to be Any value, In order that I'll be able to get the child snapshot.
I know title/id1, id3 and id3's timestamp
data structure :
title:
id1:
id2:
id3:
timestamp: 101010101
visible: true
code:
ref.child("title").child(id1).queryOrderedByKey().queryEqual(toValue: _, childKey: id3)
.observeSingleEvent(of: .value) { (snapshot) in
print(snapshot)
}
output value is null
EDIT:
Finally I solved it like that:
ref.child("title").child("id1").queryOrdered(byChild: "id3/timestamp").queryEqual(toValue: 101010101).observeSingleEvent(of: .value) { (snapshot) in
print("id2 is: ", (snapshot.value as? [String: Any])?.keys.first)
}