Firebase查询无法正常运行

时间:2017-01-19 07:42:05

标签: ios swift firebase firebase-realtime-database

我有如下的firebase结构。

enter image description here

我想要的只是那些我将通过“coach_user_id”的数据。

我的代码如下所示。

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:我们没有在firebase中应用任何规则,我不知道它是否是强制性的。

1 个答案:

答案 0 :(得分:2)

使用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.
    } 
})