swift - 基于 uid 交叉 randomKey 从 firebase 获取数据的好解决方案

标签 swift firebase firebase-realtime-database

我无法更改数据库结构。我想获得所有具有特定 uid 的匹配项作为图片。我不知道如何跨越 randomKey。我的解决方案是在节点的顶层添加一个uid,然后与randomKey下的uid进行比较。

enter image description here

最佳答案

由于您可以“添加”但不能“更改”您的结构,因此一个选项是“添加”一个子节点,该子节点代表在该匹配节点下猜测的所有猜测者 uid。顺序或计数并不重要,因为我们只想返回匹配节点(match_id_1、match_id_2 等)

matches
   match_id_1
      TzEnmFC: true
      Tss9S9i: true
      T99a0ds: true

然后执行查询匹配是用户 uid = true

let queryRef = self.ref.child("matches")
let ref = queryRef.queryOrdered(byChild: "some_uid").queryEqual(toValue: true)
ref.observe(.value, with: { snapshot in
    //do something with query results
})

关于swift - 基于 uid 交叉 randomKey 从 firebase 获取数据的好解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49183442/

相关文章:

javascript - 将地理数据从 Firebase 导入到谷歌地图

swift - 如何在 firebase 中隔离用户数据?

swift - 使用语句 For 写入元组

ios - 我无法将 UIButton 的 IBAction 连接到 ViewController 类

ios - Firebase数据库swift的权限被拒绝

ios - 我在一个页面上显示所有用户的图片和教育,如何从列表中删除当前用户?

ios - 我必须同时使用这两种方法吗?

javascript - 使用函数和 Firestore 时 FieldValue 未定义

javascript - 使用 Firebase 的 push()/childByAutoID 生成的名称的唯一性保证是什么?

ios - 在 firebase 中使用 Snap 值