swift - 火力地堡, swift : Fetch snapshot based on specific value

标签 swift firebase firebase-realtime-database

我有一个 Firebase 数据集:

  • 用户
    • QZqFzWxpdMfc0xmyIq5IDAr1bzr2
      • 证书
        • 邮箱:“myemail@gmail.com”
        • 用户名:“我的用户名”
    • RJasdfasfasdad3dadaewdsdkdq3dk
      • 证书
        • 邮箱:“another@gmail.com”
        • 用户名:“”另一个

和快照查询:

    FIRDatabase.database().reference().child("users").observe(.childAdded, with: { (snapshot) in

如何进行查询以便只返回用户名为“MyUsername”的用户的 ID?

例如我可以做类似的事情吗:

let query = "/*/credentials/[username=MyUsername]"
FIRDatabase.database().reference().child("users").child(query)

最佳答案

要仅获取与特定用户名匹配的用户节点,您需要一个查询:

FIRDatabase
  .database().reference()
  .child("users")
  .queryOrdered(byChild: "credentials/username")
  .queryEqual(toValue: "MyUsername")
  .observe(.childAdded, with: { (snapshot) in

另见 Firebase documentation on ordering and filtering data .

关于swift - 火力地堡, swift : Fetch snapshot based on specific value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45665342/

相关文章:

java - 使用 Firebase 刷新列表的最佳方法是什么

ios - 在 GCD 主要威胁中频繁调用 "tableView.reloadData"得到崩溃错误 "Index out of range"

Angular2 - 不在 'node_modules' 中查找特定模块

javascript - 如何使用 Firebase 按其子值过滤元素?

node.js - 本地 Firebase 服务器 Node 抛出 "Firebase.goOffline is not a function"

javascript - 按值查找文档而不引用其引用

android - 如何删除 Android Studio 中的重复文件

ios - 将图像从 xcode Playground 快速保存到资源文件夹

objective-c - 自动引用计数是否会在运行时产生成本

ios - setNavigationBarHidden 无法以编程方式工作?