[英]How can I write multiple data to firebase?
我在将多个数据写入 firebase 时遇到问题。 我有三个不同的 arrays,一个 int,我必须取 uid 的孩子(地址)和 uid 的名字。 以简单的方式,我想创建订单节点,并且必须将所有这些数据写入同一个节点。 我试图让它设置值,但它只需要最后一个将被删除。 我找不到任何方法来解决它。 我该如何解决?
这是我的代码:
func firebaseConfigForUserAndAdress() {
guard let uid = Auth.auth().currentUser?.uid else { return }
// these are my arrays
print(siparisEdilenUrunleriTutanArray)
print(siparisEdilenFiyatlariTutanArray)
print(siparisEdilenCountlariTutanArray)
// values for only try...
var values = siparisEdilenUrunleriTutanArray + siparisEdilenFiyatlariTutanArray
let refOrder = Database.database().reference().child("orders").child("kullanicilar").child(uid)
refOrder.setValue(values, withCompletionBlock: { (error, ref) in
if let error = error {
print("Failed to update database values with error: ", error.localizedDescription)
return
}
//self.dismiss(animated: true, completion: nil)
})
refOrder.setValue(["urun sayilari" : self.siparisEdilenCountlariTutanArray])
}
如何将这些数据写入 firebase?
我不确定我是否理解正确,但认为您可能正在寻找childByAutoId()
。 当您在某个位置调用childByAutoId()
时,Firebase 将在该位置下生成一个唯一 ID,然后您可以在其中写入数据。
对你来说,这看起来像:
let refOrder = Database.database().reference().child("orders").child("kullanicilar").child(uid)
refOrder.childByAutoId().setValue(values, withCompletionBlock: { (error, ref) in
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.