[英]Failing to Update Array in Firestore
我正在嘗試更新 Firestore 中的數組。 據我所知,你不能只是 append 到 Firestore 中的數組,而你需要用一個新數組替換整個數組。
以下是 Kotlin 中我嘗試更新數組的代碼:
holder.button.setOnClickListener {
pending.add(o[0])
Firebase.firestore.collection("profiles").document("YHMauLouORRtrYBV2h4dHJ5A0s72").update(
"Pending" , "$pending"
)
這里 o[0] 是我想要的字符串 Append 到名為 pending 的已經存在的數組
最初在 Firestore 中:-
Output 我得到:-
Output 我想要:-
基本上在更新將數組轉換為一系列列表並推送到 Firestore 時。 如何獲得如圖所示的所需 Output?
提前致謝
這不是在 Firestore 中更新數組的方法。 為此,您應該使用:
Firebase.firestore.collection("profiles")
.document("YHMauLouORRtrYBV2h4dHJ5A0s72")
.update("Pending", FieldValue.arrayUnion("Banana"))
當您在沒有第二個參數的情況下調用更新時,這意味着您要更新常規字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.