0

According to the documentation, we can not add or remove from an array in firestore, I have read a couple of methods like Alex_Answer, another answer, also after reading a couple of answers I came to the conclusion instead of reading the entire array i save the array locally when i have to change something in that array and i update the locally saved array and use Update method to in firestore too

But I don't know if my approach of updating the entire array to change one field in Custom object.

My schema is like this image. Further, groups will have students array. so instead of removing the whole array I use the following code:

db.collection("teachers").document("user").update("myGroups", groups_arrayList).
addOnCompleteListener(new OnCompleteListener<Void>() {
//done
}
  • Oh yes, we can. This [resource](https://medium.com/firebase-tips-tricks/how-to-update-an-array-of-objects-in-firestore-cdb611a56073) will help you solve that. However, I'm not sure I understand the performance problem. What's the problem with the shared code? – Alex Mamo Jul 27 '22 at 13:14
  • Thank you so much for your reply Alex, i have updated the question. I actually have read your blog which is written excellently. – irfan yaqub Jul 27 '22 at 13:19
  • So you're basically asking if it's ok to update an array of custom objects? – Alex Mamo Jul 27 '22 at 13:31
  • Yes because that array of the custom object may be changed in a way either name description or any element of the nested array has changed. Like deleting any element from the nested array. – irfan yaqub Jul 27 '22 at 15:07
  • I'm not sure I understand. What are your worries? – Alex Mamo Jul 27 '22 at 15:19
  • Alex i have update the question, will you please take a look? – irfan yaqub Jul 29 '22 at 09:40
  • What is the result of using the shared code? – Alex Mamo Jul 29 '22 at 09:48

0 Answers0