使用Swift 4中的Query查找Firebase中的数据

时间:2018-03-20 08:12:47

标签: firebase firebase-realtime-database swift4

image

let ref = Database.database().reference(withPath: "user")
ref.observeSingleEvent(of: .value, with: { snapshot in

    if !snapshot.exists() { return }

    print(snapshot) // Its print all values including Snap (User)

    print(snapshot.value!)

    let username = snapshot.childSnapshot(forPath: "full_name").value
    print(username!)

})

1 个答案:

答案 0 :(得分:2)

您需要添加查询:

ref.queryOrdered(byChild: "videoid").queryEqual(toValue: "12345").observeSingleEvent(of: .value, with: { snapshot in

更多信息:

https://firebase.google.com/docs/reference/swift/firebasedatabase/api/reference/Classes/DatabaseQuery#queryorderedbychild