0

So the structure of my Array looks like this:

Messages: [
        0:{
            email: "Johndoe@gmail.com"
            fullName: "John Doe"
            text: [
                    0: "hi there!"
                    1: "What's up?"
            ]
          }
]

I want to push a new item to the nested array "text" and I have tried several different ways with userRef.update({}).

userRef = db.collection("user").doc("email")
userRef.update({
        messages:
)}

but this is where I get stuck. I need to add to the text array where email === "johndoe@gmail.com"

I would appreciate any other idea of structuring the message Array.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • You can read more about database structure best practices here https://firebase.google.com/docs/database/web/structure-data – Andres Gardiol Dec 01 '20 at 15:09
  • It's not possible to target an array item by index. You have to read the document, modify the messages array in memory, then write the updated array back to the document. – Doug Stevenson Dec 01 '20 at 16:02

0 Answers0