【问题标题】:Add element to Firestore array将元素添加到 Firestore 数组
【发布时间】:2018-08-13 08:03:22
【问题描述】:

目前,我在 Firestore 仪表板中有一个空数组。我正在尝试向其中添加一些项目。我关注了this,但没有结果。我不想痛并重写这个元素。

我的 gradle 包含:

implementation 'com.google.firebase:firebase-firestore:17.0.4'

和我的代码:

import com.google.firebase.firestore.FieldValue

...

val documentReference = firestore.collection("events")
                .document(event.firebaseUserUid + "-" + event.title)
    documentReference
                .update("participants", (FieldValue.arrayUnion(FirebaseAuth.getInstance().currentUser!!.uid)) )

但是 FieldValue.arrayUnion 不存在。

【问题讨论】:

    标签: kotlin google-cloud-firestore


    【解决方案1】:

    我认为 Android API 实际上并未添加对此的支持,尽管它在您链接的页面上的文档是这样的。

    Android API documentation 中缺少它,但出现在 Web API documentationWeb changelog 中。

    【讨论】:

      【解决方案2】:

      最新版本的 firestore 现在支持它:

       implementation 'com.google.firebase:firebase-firestore:17.1.0'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-11
        • 2016-05-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-04
        • 1970-01-01
        • 2012-01-23
        相关资源
        最近更新 更多