Gorib Developer
Gorib Developer

Reputation: 597

Retrieve Data from Firebase using where Query in Swift 4

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!)

})

Upvotes: 5

Views: 2689

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80934

You need to add a query:

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

more info here:

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

Upvotes: 5

Related Questions