upset
The method allows setting or updating a document. It’s available on Collection
, Ref
, and Doc
.
The method returns Ref
instance:
Typesaurus accepts complete data. If the document doesn’t exist, it will set it. Otherwise, it will merge with the existing data:
It accepts a function as the argument that allows you to use the $
helper object:
$
helper
The argument function receives the $
helper object as the first argument that provides write helpers.
$
type is TypesaurusCore.WriteHelpers
.
$.serverDate
To assign a server date to a field, use $.serverDate
:
It will assign the date when Firestore saves the document.
→ Read more about server dates.
$.remove
To remove a field, use $.remove
:
Removing a field that is not optional will show you a type error.
$.increment
To increment a number field, use $.increment
:
The method is only available for the number fields.
$.arrayUnion
To add an item to an array field, use $.arrayUnion
:
The method is only available for the array fields.
$.arrayRemove
To remove an item from an array field, use $.arrayRemove
:
The method is only available for the array fields.
Options
as
You can tell Typesaurus that it’s safe to set dates to server dates by passing the as
option ("server" | "client"
):
By default, Typesaurus uses the "client"
option.