user10699313
user10699313

Reputation:

Get parent in Firebase Database

I want to get parent of a child, for do search by users in my app. How can i do that? User will enter full nickname of another user and app will give profile of this user. I understand how to find this user, but how to get UID of this user. Any ideas how can i get uid?

"app"
    "users"
          "UID"
              "name:"
              "email:"
              "nickname:"
              "uid:"

Upvotes: 0

Views: 172

Answers (1)

makata
makata

Reputation: 2258

You can easily find all users whose nickname is myNickName:

let userRef = self.ref.child("users") 

let query = userRef.queryOrdered(byChild: "nickname").queryEqual(toValue: myNickName)

query.observeSingleEvent(of: .value, with: { snapshot in
    for child in snapshot.children {

        let snap = child as! DataSnapshot
        let key = snap.key

        let dict = snap.value as! [String: Any]
        let email = dict["email"] as? String ?? "" 

        print(key)
    }
})

Upvotes: 1

Related Questions