如何使用其uid从用户检索嵌套的childByAutoId?

时间:2019-08-07 20:31:48

标签: ios swift firebase firebase-realtime-database mobile

我知道用户UID,但我想使用它的UID提取数据,UID首先用数字表示,如您在下面在Firebase Structure中看到的是ghD0lYZV1QOeJ2giUc3fNVxsLAV22并获取所有包含大量childByAutoId,其中包含-Ll7jUYg6BxRAhWPLskg

我想要UID内的所有childByAutoId值,但不知道我是朝正确的方向前进还是做错了方向, 预先感谢

 func grabbingData() {

    let specificDatabase = Database.database().reference(withPath: "Data")

    let query = specificDatabase.queryOrdered(byChild: "uid").queryEqual(toValue: "ghD0lYZV1QOeJ2giUc3fNVxsLAV2")


    query.observeSingleEvent(of: .value, with: { (snapShot) in

        for child in snapShot.children {
            if let snap = child as? DataSnapshot {
            if let dictValues = snap.value as? [String: [String: String]] {
                Array(dictValues.values).forEach {
                    let data = Data()
                    data.fullName = $0["Name"]!

                    data.Data = $0["Data"]!


                    self.grabbingRequest.append(data)


                }



            }
            }
        }
    })







            self.tableView.reloadData()

    }

Firebase Data Structure   
 "Data" : {
  "ghD0lYZV1QOeJ2giUc3fNVxsLAV2" : {
    "-Ll7jUYg6BxRAhWPLskg" : {
      "Name" : "other Martin",
      "Data1" : "data"
     },
    "-Ll7jW_elQIPTLESwDYD" : {
      "Name" : "other Martin",
      "Data1" : "data "
     }
   },
}

0 个答案:

没有答案