0

I am making a Twitter clone and here is my database enter image description here

I want to update the likes field by increasing its value to 1 when the user clicks on the like button,

Can anyone suggest me how can I update the like field?

Manish Panwar
  • 25
  • 1
  • 6
  • This **[anwer](https://stackoverflow.com/questions/60866021/is-that-possible-to-update-firestore-document-child-array-item-only)** will help. – Alex Mamo Dec 22 '20 at 12:10
  • This structure doesn't look good to me. If your app is successful then this won't scale at all. You're storing all the tweet data in one single document. A doc has a limit of 20k fields, so you're looking for trouble in a way. In your shoes, I would use a structure like: users(collection) / user (document) / tweets (subcollection) / {tweetId} (document) – MarketerInCoderClothes Dec 22 '20 at 14:42
  • There is no built-in operation to update an item in an array. You'll have to 1) read the document, 2) update the array in your application code, 3) write the entire array back to the database. This has been covered quite a few times already, so I recommend reading some of these: https://stackoverflow.com/search?q=%5Bgoogle-cloud-firestore%5D+update+item+in+array – Frank van Puffelen Dec 22 '20 at 15:47

0 Answers0