Reputation: 8701
Let's say I have an array stored in a Firestore document and the order matters. e.g. :
//Hypothetically stored in firebase.firestore().collection('collection').doc('doc')
array_info: [{1:a}, {2:b}, {3:c}]
And let's say I want to update an array element while preserving the order. e.g. I want to update {2:b} to {2:d}, while preserving its state as the second entry.
I thought about using arrayRemove and arrayUnion, but then it would not preserve the order. I also thought about some backend operations, using cloud functions, like downloading an entire array, modify it as I'd like, and store them again, but that would be taking some time and will incur an additional read count.
Wondering if there is any native method in Firestore to deal with this situation? Looked at the documentations but I cannot find one. Any advice? Will be appreciated!
Upvotes: 0
Views: 180
Reputation: 317372
Firestore does not provide operations to modify array elements in place. You will have to read the document, make changes to the array in memory, then write the field back to the document.
Upvotes: 1