2

I'm trying to implement firestore into my flutter app. My documents on firestore have an array field which has objects. These objects have an array too. It looks like this:

Topics[
 {
  "id": "1234"
  "questions": [] <-- This field I want to update
 }
]

I know that I can update fields with the updateData() function of myDocument.reference. There I can update my value inside an array like this:

mydocument.reference.updateData({
 "topics.id": 1
})

This works fine for easy structures but what I need is to get a specific index of the topics array where I get the object an its questions array which I want to update. Something like this:

document.reference.updateData({
      "topics[$index].questions": FieldValue.arrayUnion([q])
    });
Funkberater
  • 775
  • 8
  • 16
  • 2
    You can't do this with Cloud Firestore. You will have to read the document, modify the array in memory, then write the document back out. Or, you can not use an array and choose and object with string fields instead. – Doug Stevenson Jun 10 '19 at 16:24

0 Answers0