[英]Firebase - accessing child node when you don't know the value of the parent key - generated by childByAutoId()
I have the following structure in my firebase database. 我的firebase数据库中有以下结构。
"friendRequest" : {
"uid" : {
"-KUT7mxTW7WGLkgrZVM4" : {
"fromUid" : "uid"
}
}
}
In my iOS app, a user can make a friend request, similar in principle to adding friends on Facebook. 在我的iOS应用程序中,用户可以发出好友请求,原则上类似于在Facebook上添加好友。
I need to access the fromUid property but I don't know the parent key above it which is generated by childByAutoId() (the third line - "-KUT7mxTW7WGLkgrZVM4"). 我需要访问fromUid属性,但我不知道它上面的父键是由childByAutoId()生成的(第三行 - “-KUT7mxTW7WGLkgrZVM4”)。
How can I access the fromUid
key to get its value? 如何访问
fromUid
键以获取其值?
I think you're looking for something like: 我想你正在寻找类似的东西:
ref.child("friendRequest")
.child(FIRAuth.auth()?.currentUser.uid)
.queryOrdered(byChild: "fromId")
.queryEqual(toValue: "theUidThatYou'reLookingFor")
.observeSingleEvent(of: .childAdded, with: { (snapshot) in
print("\(snapshot.key)")
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.