Edit: The answer was initially Yes, however, with updated information
from the OP, both the parent node 'deaf...' and child node '1248...'
are both unknowns so there would be no way to craft a deep query.
If the child node '1248' was consistent as the key for each child node of the deaf... node then the answer is yes.
Yes, you can certainly get the parent node as well as the parent's parent. This is Swift since the platform was not specified but the concept is the same across the board.
Given a structure
root
posts
post_1
details
posted_by: "Leroy"
post_2
details
posted_by: "Bill"
Let's do a query for the Leroy node via a deep query:
let postsRef = ref.child("posts")
let queryRef = dataRef.queryOrdered(byChild: "details/posted_by")
.queryEqual(toValue: "Leroy")
queryRef.observeSingleEvent(of: .value, with: { (snapshot) in
let a = snapshot.key //the posts node
print(a)
for child in snapshot.children {
let childSnap = child as! FIRDataSnapshot
print(childSnap.key) //the direct parent node
}
})
and the result will print
posts
post_1
Another option is to include the parent node in the lower level node like this
root
deaf91298823
1248
email: "asad@asdd.com"
name: "Adam"
parent_node: "1248"
parent_parent: "deaf91298823"