Skip to content

React - Write Functions

Standalone functions for creating, updating, and deleting documents without fetching them first. Useful when you already know the document path and just want to write.

API Reference

FunctionDescription
setDocumentCreate or overwrite a document (supports merge)
setSpecificDocumentCreate or overwrite a specific document
updateDocumentPartially update an existing document
updateSpecificDocumentPartially update an existing specific document
deleteDocumentDelete a document
deleteSpecificDocumentDelete a specific document

The set* functions accept an optional SetOptions parameter for { merge: true } or { mergeFields: [...] } behavior. The *Specific* variants accept a DocumentReference directly instead of a collection ref + id.

A Note on Client-Side Mutations

This library provides both document-level mutation methods (on FsMutableDocument) and standalone write functions for performing client-side writes.

That said, consider having all mutations happen on the server-side via an API call. This is especially relevant if older versions of your app could be around for a while, like with mobile apps. A bug in client-side code could have lasting effects on the consistency of your database.

Facilitating client-side writes in a safe way also requires writing database rules for your documents, which can get very complex. Mutating documents server-side is not only easier to reason about but also more secure by default.

Released under the Apache-2.0 License.