Reputation: 4373
I have firebase structure like below.
All I want is those data whose "coach_user_id" I will pass.
My code is like below.
let ref1 = self.dbRef.child(activity).queryOrdered(byChild: "coach_user_id")
ref1.queryEqual(toValue: "33", childKey: "coach_user_id").observe(.childAdded) { (snapshot :FIRDataSnapshot?) in
if let values : Dictionary<String,AnyObject> = snapshot?.value as? Dictionary<String,AnyObject>
{
}
}
PS: We did not apply any rules in firebase, I don't know if it is compulsory or not.
Upvotes: 0
Views: 649
Reputation: 22374
Try this with queryOrderedByChild
let ref = self.dbRef.child("activity")
ref?.queryOrdered(byChild: "coach_user_id").queryEqual(toValue: "33").observe(.childAdded, with: { snapshot in
if let activity = snapshot.value as? [String : Any] {
// do stuff with 'activity' here.
}
})
Upvotes: 2