Updating Arrays with Firestore
Firestore offers a straightforward method for updating arrays within documents, eliminating the need for overwriting the entire array.
The following functions enable array updates:
Example code:
// Array union firebase.firestore() .collection('proprietary') .doc(docID) .update({ sharedWith: firebase.firestore.FieldValue.arrayUnion({ who: "[email protected]", when: new Date() }) }) // Array remove firebase.firestore() .collection('proprietary') .doc(docID) .update({ sharedWith: firebase.firestore.FieldValue.arrayRemove({ who: "[email protected]", when: new Date() }) })
These functions provide a simple and efficient way to manage arrays in Firestore, allowing developers to make targeted updates without affecting the entire array.
The above is the detailed content of How can I efficiently update arrays within Firestore documents without overwriting the whole array?. For more information, please follow other related articles on the PHP Chinese website!