Ios Swift Firebase-如何在使用queryOrdered(byChild:)时获取所有k/v。queryEqual(toValue:)

Ios Swift Firebase-如何在使用queryOrdered(byChild:)时获取所有k/v。queryEqual(toValue:),ios,swift,firebase,firebase-realtime-database,Ios,Swift,Firebase,Firebase Realtime Database,我的数据库设置如上所述。有时候我只有买家uid,所以我只能提取我使用的数据 一旦我找到与买方关联的所有其他k/v,如何在该节点下获取它们 具有内置的方法来循环其子级 let reviewsRef = Database.database().reference()? .child("reviews") .child("postABC") .queryOrdered(byChild: "

我的数据库设置如上所述。有时候我只有买家uid,所以我只能提取我使用的数据

一旦我找到与买方关联的所有其他k/v,如何在该节点下获取它们

具有内置的方法来循环其子级

let reviewsRef = Database.database().reference()?
                   .child("reviews")
                   .child("postABC")
                   .queryOrdered(byChild: "buyerUID")
                   .queryEqual(toValue: "01010")

reviewsRef?.observeSingleEvent(of: .value, with: { [weak self](snapshot) in

    print(snapshot.key) // prints  postABC
    print(snapshot.value) // prints a dictionary with reviewXYZ as the key and everything underneath it as a value

    guard let dict = snapshot.value as? [String: Any] else { return }
})

另请参阅其他。

谢谢,它成功了。对于在For循环中使用此选项的任何其他人,只需将child转换为Datasnapshot。例如-对于snapshot.children{let x=child as!DataSnapshot;printx.key;printx.value;printx.childSnapshotforPath:“buyeyud.value}感谢您分享正确的咒语!我更新了我的答案以反映这一点。由于您添加了datasnapshot,您可能希望删除您所说的可能缺少它的句子。这可能会让一些人感到困惑
let reviewsRef = Database.database().reference()?
                   .child("reviews")
                   .child("postABC")
                   .queryOrdered(byChild: "buyerUID")
                   .queryEqual(toValue: "01010")

reviewsRef?.observeSingleEvent(of: .value, with: { [weak self](snapshot) in

    print(snapshot.key) // prints  postABC
    print(snapshot.value) // prints a dictionary with reviewXYZ as the key and everything underneath it as a value

    guard let dict = snapshot.value as? [String: Any] else { return }
})
reviewsRef?.observeSingleEvent(of: .value, with: { [weak self](snapshot) in
  for child in snapshot.children {
    let snap = child as! DataSnapshot;
    print(snap.key)
    print(snap.value) 
    print(snap.childSnapshot(forPath: "buyerUID").value)
  }
})