如何在Firestore中更新地图数组中的元素? [英] How to update elements in arrays of maps in Firestore?

查看:53
本文介绍了如何在Firestore中更新地图数组中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有一个Android应用程序(java),该应用程序可以访问包含数组字段的firestore文档,如下所示:

I have and Android App (java) that accesses firestore documents that comprise of an array field as shown:

{
  cards: 
    [
      {
        reference: "",
        response: {
                    text: "",
                    title: "",
                  },
        timestamp: ""
      },

      {
        reference: "",
        response: {
                    text: "",
                    title: "",
                  },
        timestamp: ""
      },

     .... and so on

我想更新每个数组元素的特定字段,例如"response":"text"和"response":"title".实现此目标的最佳方法是什么?

I would like to update specific fields of each array element, like "response" : "text" and "response" : "title". What is the best way to achieve this?

我在多个地方都读到不能在元素级别更新数组,并且可能必须完全覆盖整个数组.真的吗?是的,我该如何在Android(Java)中构造相同的更新语句?

I have read in several places that arrays cannot be updated at element level and that I may have to completely overwrite the entire array. Is that true? Is so, how can I construct my update statement in Android (Java) for the same?

谢谢

AB

推荐答案

您已阅读的内容是正确的.当前无法通过其索引简单请求更新数组字段项.您将必须阅读文档,对内存中的数组进行更改,然后使用新的字段内容更新文档.这一切非常简单,有关查询和<一个href ="https://firebase.google.com/docs/firestore/manage-data/add-data" rel ="nofollow noreferrer">更新文档.

The things you have read are true. It's currently not possible to make a simple request to update an array field item by its index. You will have to read the document, make changes to the array in memory, then update the document with the new field contents. This is all very straightforward and covered by the documentation about querying and updating documents.

这篇关于如何在Firestore中更新地图数组中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆