通过儿童价值的孩子搜索firebase [英] Search firebase by Child of child value
问题描述
是否有可能通过电子邮件地址查询a@a.com并检索1248769d7j8以及其父母deaf7834jd8d7j-78?
我的解决方案是使数据库结构更平坦。但我想知道是否有可能通过非规范化获得更新:在我的情况下,124 ...和dea ...都是未知的,唯一的ID
编辑:答案最初是的,然而,从OP获得更新信息
,父节点'deaf ...'和子节点'1248 ...'
都是未知数,所以不可能创建一个深层的查询。
如果子节点1248一致作为聋节点的每个子节点的关键字,那么答案是肯定的。
是的,你当然可以得到父节点以及父节点的父节点。这是Swift,因为没有指定平台,但概念是相同的。
给定一个结构
root
$ b $ posted_by:Bill
让我们通过深层查询来查询Leroy节点:
let postsRef = ref.child(posts)
let queryRef = dataRef.queryOrdered(byChild:
.queryEqual(toValue:Leroy)
queryRef.observeSingleEvent(of:.value,with:{(snapshot)in
let a = snapshot.key // $ node
print(a)
在snapshot.children中的子元素{
let childSnap = child as!FIRDataSnapshot
print(childSnap.key)//直接父节点
})
p>
post
post_1
另一个选项是将父节点包含在较低级别的节点中
root
deaf91298823
1248
电子邮件:asad@asdd.com
name:Adam
parent_node:1248
parent_parent:deaf91298823
I have a firebase database structure similar to this
Is it possible to query by the email address say "a@a.com" and retrieve both the keys "1248769d7j8" as well its parent "deaf7834jd8d7j-78" ?
The solution I have is to make the database structure flatter. But am wondering if it is possible to get by without denormalization
Update: In my case both 124... and dea... are unknown, unique IDs
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"
这篇关于通过儿童价值的孩子搜索firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!