2

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

Abhishek Sharma
  • 609
  • 1
  • 11
  • 22

1 Answers1

2

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.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441