0

I have this array with an object inside and would like to update said so that there is some text inside.

enter image description here

code:

ratePost (postId, postLikes) {
  let docId = `${this.currentUser.uid}`

  fb.usersCollection.doc(docId).update({
    gotRates: [
      { said: postLikes }
    ]
  })
  .then(() => {
    console.log('work')
  })
}

But this will only overwrite the whole array.

Lukas
  • 573
  • 2
  • 8
  • 19

1 Answers1

2

You need to use set and not update, with merge as true, to make sure you don't overwrite the whole array, check the set documentation here https://firebase.google.com/docs/firestore/manage-data/add-data

ratePost (postId, postLikes) {
  let docId = `${this.currentUser.uid}/gotRates/0`

  fb.usersCollection.doc(docId).update({
    said: postLikes
  })
  .then(() => {
    console.log('work')
  })
}
Dinosan0908
  • 1,082
  • 2
  • 8
  • 19