iphone - 我想通过用户名在 firebase 中搜索

标签 iphone swift xcode firebase firebase-realtime-database

我在检索节点中存在的数据时遇到问题

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"
                    }
            }
     }
  }

数据库结构

see the structure

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/

相关文章:

ios - 未指定数据类型时 Swift 变量为 nil

Swift:在所有屏幕上具有共享标题的 UITabBar

xcode - OCLint 生成 html 报告

iphone - commitEditingStyle 的问题 - 删除表中的单元格

iphone - 在ios通讯录中存储经纬度

ios - 为什么 UITextField 占位符文本的大小变小了?

iphone - 可以从中国将二进制文件上传到 iTunes Connect 吗?

ios - 如何删除数组中的一个重复值?

ios - Xcode文件权限问题

ios - Swift 1.2 的 Alamofire 生成错误