用户

时间:2017-05-20 04:21:07

标签: swift firebase firebase-realtime-database

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

enter image description here

我正在使用这行代码:

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

这行代码返回null - 意味着它没有找到" jondoe"作为用户节点中的用户名。我如何让它工作?

1 个答案:

答案 0 :(得分:1)

两个问题:

  1. 类型usernames vs username
  2. 您正在尝试查询更深层的属性,但只显示属性名称而不是其路径
  3. 这应该更好:

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