Usage
The firestoreMerge function allows for merging updates to a document within a Firestore collection. The primary use case is to update fields in a document without overwriting the entire document. This is especially useful for partial updates.
Usage is straightforward:
Subcollections
firestoreMerge can also handle subcollections. To update a document in a subcollection, the collection path must include the subcollection path:
Dynamic Paths
For more dynamic use cases, you can use a function to determine the collection path:
Return Value
The firestoreMerge function returns a Promise that resolves to a DocumentReference of the merged document:
Type Safety
When a type parameter is provided, the function ensures type safety for the data being merged:
Although type definitions help prevent mistakes, they are not a guarantee
against invalid data. Ensure proper usage of the function for accurate data
updates.
Options
You can also include metadata when merging data by using the addMetadata option.