Yash R
Yash R

Reputation: 247

Swift 3 How to get specific user id in firebase

I am using firebase as backend and I want all user id with status false.

My Data

What I am trying in my code:-

ref.child("users").child((Auth.auth().currentUser?.uid)!).child("status").queryOrdered(byChild: "status").queryEqual(toValue : "false").observe(.value) { (snapshot: DataSnapshot) in

        if let snapshot = snapshot.children.allObjects as? [DataSnapshot] {
            print("SNAPSHOT: \(snapshot)")

            for snap in snapshot {
                if let postDict = snap.value as? Dictionary<String, AnyObject> {
                    let key = snap.key
                    print(key)
                    print(postDict)
                }
            }
        }
    }

Upvotes: 0

Views: 1669

Answers (1)

Vinit Ingale
Vinit Ingale

Reputation: 401

Find sample code below. Just verify syntax once.

   ref.child("users").observe(DataEventType.value, with: { (snapshot) in

    if let snapshot = snapshot.children.allObjects as? [DataSnapshot] {
        print("SNAPSHOT: \(snapshot)")

        for snap in snapshot {
            if let userDict = snap.value as? Dictionary<String, AnyObject> {

               if userDict["Status"] as? Bool == false {
               let key = snap.key
               print(key)
               //Add this key to userID array
               }
            }
        }
    }
}

Upvotes: 1

Related Questions