[英]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.