Firebase:过滤嵌套查询无效

时间:2017-08-24 02:52:02

标签: swift firebase firebase-realtime-database geofire

我正在尝试在Firebase上执行SQL等效的连接查询,但我希望仅当密钥privacy等于public时才加入。

以下代码不会将结果返回给我。如果我删除child(key)然后它工作正常,但它将不会加入。我真的很喜欢这方面的帮助。

circleQuery?.observe(.keyEntered, with: { (key: String!, location: CLLocation!) in

    self.locationRef.child(key).queryOrdered(byChild: "privacy").queryEqual(toValue : "public").observeSingleEvent(of: .value, with: { (locationSnapshot) in
        if !locationSnapshot.exists() { return }

        // returns no results
    }) { (error) in
        print(error.localizedDescription)
    }

})

1 个答案:

答案 0 :(得分:0)

在firebase中使用以下方法在查询的基础上发布并获得结果

   let databaseReff = Database.database().reference().child("your parent node in which query will be searched and compared")

                databaseReff.queryOrdered(byChild: "fromId // parameter whose value will be checked").queryEqual(toValue: self.requiredID //Parameter which will be compared).observe(.value, with: { snapshot in
                    if snapshot.exists(){

                        print(snapshot.value!) //print full snapshot
                        if let snapDict:[String:AnyObject] = snapshot.value as? [String : AnyObject] {

                            let dictKeys = [String](snapDict.keys)
                            print(dictKeys) //print all the nodes that will satisfy your query

                        }

                    }


                })