Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift Firebase查询数据库为用户名返回null_Swift_Firebase_Firebase Realtime Database - Fatal编程技术网

Swift Firebase查询数据库为用户名返回null

Swift Firebase查询数据库为用户名返回null,swift,firebase,firebase-realtime-database,Swift,Firebase,Firebase Realtime Database,我正在尝试查询此数据库: 我正在使用这行代码: databaseReference.child("users").queryOrdered(byChild: "username").queryEqual(toValue: "billsmith").observeSingleEvent(of: .value, with: { (snap) in print(snap) }) 这一行代码返回null——这意味着它在用户节点中找不到“jondoe”作为用户名。如何使其工作?有两个问题: 类

我正在尝试查询此数据库:

我正在使用这行代码:

databaseReference.child("users").queryOrdered(byChild: "username").queryEqual(toValue: "billsmith").observeSingleEvent(of: .value, with: { (snap) in
    print(snap)
})
这一行代码返回null——这意味着它在用户节点中找不到“jondoe”作为用户名。如何使其工作?

有两个问题:

  • 类型
    用户名
    vs
    用户名
  • 您试图查询更深层的属性,但只显示属性名称而不是其路径
  • 这应该更好地发挥作用:

    databaseReference
      .queryOrdered(byChild: "userDetails/username")
      .queryEqual(toValue: "billsmith")
      .observeSingleEvent(of: .value, with: { (snap) in
        print(snap)
      })
    

    byChild:“usernames”
    应该是
    byChild:“username”
    以匹配输入错误的数据库-感谢您的帮助!在我的问题中,我在代码中输入了一些错误,所以我通过添加.child(“用户”)来编辑答案,但这很有效,谢谢!有没有地方让我学习更多关于查询的知识?我在查询时找不到一些文档。如果文档没有足够的帮助,我建议您查看堆栈溢出相关问题。到目前为止,他们中一定有不少人。