Write

A write on a document.

JSON representation
{
  "updateMask": {
    object(DocumentMask)
  },
  "currentDocument": {
    object(Precondition)
  },

  // Union field operation can be only one of the following:
  "update": {
    object(Document)
  },
  "delete": string,
  "transform": {
    object(DocumentTransform)
  }
  // End of list of possible types for union field operation.
}
Fields
updateMask

object(DocumentMask)

The fields to update in this write.

This field can be set only when the operation is update. If the mask is not set for an update and the document exists, any existing data will be overwritten. If the mask is set and the document on the server has fields not covered by the mask, they are left unchanged. Fields referenced in the mask, but not present in the input document, are deleted from the document on the server. The field paths in this mask must not contain a reserved field name.

currentDocument

object(Precondition)

An optional precondition on the document.

The write will fail if this is set and not met by the target document.

Union field operation. The operation to execute. operation can be only one of the following:
update

object(Document)

A document to write.

delete

string

A document name to delete. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}.

transform

object(DocumentTransform)

Applies a tranformation to a document. At most one transform per document is allowed in a given request. An update cannot follow a transform on the same document in a given request.

DocumentTransform

A transformation of a document.

JSON representation
{
  "document": string,
  "fieldTransforms": [
    {
      object(FieldTransform)
    }
  ]
}
Fields
document

string

The name of the document to transform.

fieldTransforms[]

object(FieldTransform)

The list of transformations to apply to the fields of the document, in order. This must not be empty.

FieldTransform

A transformation of a field of the document.

JSON representation
{
  "fieldPath": string,

  // Union field transform_type can be only one of the following:
  "setToServerValue": enum(ServerValue),
  "appendMissingElements": {
    object(ArrayValue)
  },
  "removeAllFromArray": {
    object(ArrayValue)
  }
  // End of list of possible types for union field transform_type.
}
Fields
fieldPath

string

The path of the field. See Document.fields for the field path syntax reference.

Union field transform_type. The transformation to apply on the field. transform_type can be only one of the following:
setToServerValue

enum(ServerValue)

Sets the field to the given server value.

appendMissingElements

object(ArrayValue)

Append the given elements in order if they are not already present in the current field value. If the field is not an array, or if the field does not yet exist, it is first set to the empty array.

Equivalent numbers of different types (e.g. 3L and 3.0) are considered equal when checking if a value is missing. NaN is equal to NaN, and Null is equal to Null. If the input contains multiple equivalent values, only the first will be considered.

The corresponding transform_result will be the null value.

removeAllFromArray

object(ArrayValue)

Remove all of the given elements from the array in the field. If the field is not an array, or if the field does not yet exist, it is set to the empty array.

Equivalent numbers of the different types (e.g. 3L and 3.0) are considered equal when deciding whether an element should be removed. NaN is equal to NaN, and Null is equal to Null. This will remove all equivalent values if there are duplicates.

The corresponding transform_result will be the null value.

ServerValue

A value that is calculated by the server.

Enums
SERVER_VALUE_UNSPECIFIED Unspecified. This value must not be used.
REQUEST_TIME The time at which the server processed the request, with millisecond precision.
Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Firestore