我在检索节点中存在的数据时遇到问题
Dev->Regis->[userId("hjgsfgsdfghd8ydfsw3r")]->UserInfo->{userName:"", email:""}
我正在尝试以下查询
ref.child(kChild).child(kRegistration).queryOrdered(byChild: kUserInfo).queryEqual(toValue: searchText).observeSingleEvent(of: .value) { (snapshot) in
if snapshot.exists() {
}
}
我也尝试制定规则,但确实产生了结果
"Development": {
"Registration": {
"$user_id": {
"UserInfo": {
".indexOn": ["userName"],
".read": "auth.uid == $user_id"
}
}
}
}
数据库结构
ref 表示 Database.refrence()
请帮忙解决这个问题。
谢谢。
最佳答案
假设 searchText 是您要抓取对象的用户名值。 Firebase 需要 orderBy 调用。
let searchText = //username you wish to fetch
let ref = db.ref('Development/Registration/${userId}/userInfo')
ref.orderByChild('userName').equalTo(searchText).once("value", function(snapshot) {
if(snapshot.exists()){
//whatever you want to do here
}
}
关于iphone - 我想通过用户名在 firebase 中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51908257/