Skip to content

Reserved Keywords

Gauthier Dandele edited this page Aug 12, 2024 · 1 revision

The following reserved keywords are used as Sentinel values for write request:

Caution

None of these reserved keywords can be used into an array. This is a limitation of Firestore.

Array Union

To union the given elements with any array value that already exists on the server. Each specified element that doesn't already exist in the array will be added to the end. If the field being modified is not already an array it will be overwritten with an array containing exactly the specified elements.

Usage

The keyword must be used as a key in an object and its value will be added to the array:

{
  "ARRAY_UNION": "some-value"
}

Example

The following example adds the string "foo" to the array "my-array":

{
  "my-array": {
    "ARRAY_UNION": "foo"
  }
}

Array Remove

To remove the given elements from any array value that already exists on the server. All instances of each element specified will be removed from the array. If the field being modified is not already an array it will be overwritten with an empty array.

Usage

The keyword must be used as a key in an object and its value will be added to the array:

{
  "ARRAY_REMOVE": "some-value"
}

Example

The following example removes the string "foo" from the array "my-array":

{
  "my-array": {
    "ARRAY_REMOVE": "foo"
  }
}

Decrement/Increment

To decrement/increment the field's current value by the given value. The value must be a number.

Usage

The keyword must be used as the following string: INCREMENT [delta] or DECREMENT [delta].

Example

The following example increments by 2 the value of "index":

{
  "index": "INCREMENT 2"
}

Delete

To mark a field for deletion.

Usage

The keyword must be used as the following string: DELETE.

Example

The following example deletes the "field-to-keep" field and it's value from the object:

{
  "field-to-delete": "DELETE"
}

Geo Point

To include a server-generated Geo Point in the written data.

Usage

The keyword must be used as the following object:

{
  "GEO_POINT": {
    "latitude": 90,
    "longitude": 90
  }
}

Example

The following example defines a Geo Point for the "location" field:

{
  "location": {
    "GEO_POINT": {
      "latitude": 90,
      "longitude": 90
    }
  }
}

Timestamp

To include a server-generated timestamp in the written data.

Usage

The keyword must be used as the following string: TIMESTAMP.

Example

The following example defines the value of "date":

{
  "date": "TIMESTAMP"
}