How to update elements in arrays of maps in Firestore?

…衆ロ難τιáo~ 提交于 2021-02-04 08:28:52

问题


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

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?

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?

Thanks,

AB


回答1:


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.



来源:https://stackoverflow.com/questions/58719927/how-to-update-elements-in-arrays-of-maps-in-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!