繁体   English   中英

无法在 Firestore 中更新阵列

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM