Im using Google Firestore with Angular and I'm trying to update a specific element inside an array.
I've tried a lot of things but with no succsess at all.
How can I reach to the specific company index inside the companies array?
Thanks :)
Im using Google Firestore with Angular and I'm trying to update a specific element inside an array.
I've tried a lot of things but with no succsess at all.
How can I reach to the specific company index inside the companies array?
Thanks :)
How can I reach to the specific company index inside the companies array?
There is no way you can get, update or remove an element in a Firestore array according with the corresponding index. Try to think what might happen if a user wants to edit a value at index 0, some other user wants to delete the value at index 0 and in the same time another user wants to add another value at index 1, you'll end up having very different results and why not, an ArrayIndexOutOfBoundsException. So Firestore actions with arrays are a little bit different. So you cannot perform actions like, insert, update or delete at a specific index. So use arrays only if don't care about the exact order that you store elements.
Firestore added a few weeks ago some features to add or remove specific elements but only if don't care about the exact position of them. See here official documentation.
In your case, you don't have a simple array of strings you have an array of objects, which means that in order to do some chnages, you should get the entire object, iterate over the properties, make the necessary changes and write it back to the database.