Reference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::FieldValue.
FieldValue
Represents a change to be made to fields in document data in the
Firestore API.
Inherits
Object
Example
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Get a document referencenyc_ref=firestore.doc"cities/NYC"# Set the population to increment by 1.increment_value=Google::Cloud::Firestore::FieldValue.increment1nyc_ref.update({name:"New York City",population:increment_value})
Methods
.array_delete
defself.array_delete(*values)->FieldValue
Creates a sentinel value to indicate the removal of the given values
with an array.
Parameter
values (Object) — The values to remove from the array. Required.
Returns
(FieldValue) — The array delete field value object.
Raises
(ArgumentError)
Example
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Get a document referencenyc_ref=firestore.doc"cities/NYC"array_delete=Google::Cloud::Firestore::FieldValue.array_delete(7,8,9)nyc_ref.update({name:"New York City",lucky_numbers:array_delete})
.array_union
defself.array_union(*values)->FieldValue
Creates a sentinel value to indicate the union of the given value
with an array.
Parameter
values (Object) — The values to add to the array. Required.
Returns
(FieldValue) — The array union field value object.
Raises
(ArgumentError)
Example
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Get a document referencenyc_ref=firestore.doc"cities/NYC"array_union=Google::Cloud::Firestore::FieldValue.array_union(1,2,3)nyc_ref.update({name:"New York City",lucky_numbers:array_union})
.delete
defself.delete()->FieldValue
Creates a field value object representing the deletion of a field in
document data.
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Get a document referencenyc_ref=firestore.doc"cities/NYC"field_delete=Google::Cloud::Firestore::FieldValue.deletenyc_ref.update({name:"New York City",trash:field_delete})
.increment
defself.increment(value)->FieldValue
Creates a sentinel value to indicate the addition the given value to
the field's current value.
If the field's current value is not an integer or a double value
(Numeric), or if the field does not yet exist, the transformation will
set the field to the given value. If either of the given value or the
current field value are doubles, both values will be interpreted as
doubles. Double arithmetic and representation of double values follow
IEEE 754 semantics. If there is positive/negative integer overflow,
the field is resolved to the largest magnitude positive/negative
integer.
Parameter
value (Numeric) — The value to add to the given value. Required.
(ArgumentError) — if the value is not an Integer or Numeric.
Example
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Get a document referencenyc_ref=firestore.doc"cities/NYC"# Set the population to increment by 1.increment_value=Google::Cloud::Firestore::FieldValue.increment1nyc_ref.update({name:"New York City",population:increment_value})
.maximum
defself.maximum(value)->FieldValue
Creates a sentinel value to indicate the setting the field to the
maximum of its current value and the given value.
If the field is not an integer or double (Numeric), or if the field
does not yet exist, the transformation will set the field to the given
value. If a maximum operation is applied where the field and the input
value are of mixed types (that is - one is an integer and one is a
double) the field takes on the type of the larger operand. If the
operands are equivalent (e.g. 3 and 3.0), the field does not change.
0, 0.0, and -0.0 are all zero. The maximum of a zero stored value and
zero input value is always the stored value. The maximum of any
numeric value x and NaN is NaN.
Parameter
value (Numeric) — The value to compare against the given value to
calculate the maximum value to set. Required.
(ArgumentError) — if the value is not an Integer or Numeric.
Example
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Get a document referencenyc_ref=firestore.doc"cities/NYC"# Set the population to be at maximum 4,000,000.maximum_value=Google::Cloud::Firestore::FieldValue.maximum4000000nyc_ref.update({name:"New York City",population:maximum_value})
.minimum
defself.minimum(value)->FieldValue
Creates a sentinel value to indicate the setting the field to the
minimum of its current value and the given value.
If the field is not an integer or double (Numeric), or if the field
does not yet exist, the transformation will set the field to the input
value. If a minimum operation is applied where the field and the input
value are of mixed types (that is - one is an integer and one is a
double) the field takes on the type of the smaller operand. If the
operands are equivalent (e.g. 3 and 3.0), the field does not change.
0, 0.0, and -0.0 are all zero. The minimum of a zero stored value and
zero input value is always the stored value. The minimum of any
numeric value x and NaN is NaN.
Parameter
value (Numeric) — The value to compare against the given value to
calculate the minimum value to set. Required.
(ArgumentError) — if the value is not an Integer or Numeric.
Example
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Get a document referencenyc_ref=firestore.doc"cities/NYC"# Set the population to be at minimum 1,000,000.minimum_value=Google::Cloud::Firestore::FieldValue.minimum1000000nyc_ref.update({name:"New York City",population:minimum_value})
.server_time
defself.server_time()->FieldValue
Creates a field value object representing set a field's value to
the server timestamp when accessing the document data.
Returns
(FieldValue) — The server time field value object.
Example
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Get a document referencenyc_ref=firestore.doc"cities/NYC"field_server_time=Google::Cloud::Firestore::FieldValue.server_timenyc_ref.update({name:"New York City",updated_at:field_server_time})
#type
deftype()->Symbol
The type of change to make to an individual field in document data.
Returns
(Symbol) — The type.
Example
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Get a document referencenyc_ref=firestore.doc"cities/NYC"field_delete=Google::Cloud::Firestore::FieldValue.deletefield_delete.type#=> :deletenyc_ref.update({name:"New York City",trash:field_delete})
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-09 UTC."],[],[],null,["# Cloud Firestore API - Class Google::Cloud::Firestore::FieldValue (v3.1.0)\n\nVersion latestkeyboard_arrow_down\n\n- [3.1.0 (latest)](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-FieldValue)\n- [3.0.0](/ruby/docs/reference/google-cloud-firestore/3.0.0/Google-Cloud-Firestore-FieldValue)\n- [2.16.1](/ruby/docs/reference/google-cloud-firestore/2.16.1/Google-Cloud-Firestore-FieldValue)\n- [2.15.1](/ruby/docs/reference/google-cloud-firestore/2.15.1/Google-Cloud-Firestore-FieldValue)\n- [2.14.0](/ruby/docs/reference/google-cloud-firestore/2.14.0/Google-Cloud-Firestore-FieldValue)\n- [2.13.1](/ruby/docs/reference/google-cloud-firestore/2.13.1/Google-Cloud-Firestore-FieldValue)\n- [2.12.0](/ruby/docs/reference/google-cloud-firestore/2.12.0/Google-Cloud-Firestore-FieldValue)\n- [2.11.0](/ruby/docs/reference/google-cloud-firestore/2.11.0/Google-Cloud-Firestore-FieldValue)\n- [2.10.1](/ruby/docs/reference/google-cloud-firestore/2.10.1/Google-Cloud-Firestore-FieldValue)\n- [2.9.1](/ruby/docs/reference/google-cloud-firestore/2.9.1/Google-Cloud-Firestore-FieldValue)\n- [2.8.0](/ruby/docs/reference/google-cloud-firestore/2.8.0/Google-Cloud-Firestore-FieldValue)\n- [2.7.2](/ruby/docs/reference/google-cloud-firestore/2.7.2/Google-Cloud-Firestore-FieldValue)\n- [2.6.6](/ruby/docs/reference/google-cloud-firestore/2.6.6/Google-Cloud-Firestore-FieldValue) \nReference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::FieldValue.\n\nFieldValue\n----------\n\nRepresents a change to be made to fields in document data in the\nFirestore API. \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Get a document reference\nnyc_ref = firestore.doc \"cities/NYC\"\n\n# Set the population to increment by 1.\nincrement_value = Google::Cloud::Firestore::FieldValue.increment 1\n\nnyc_ref.update({ name: \"New York City\",\n population: increment_value })\n```\n\nMethods\n-------\n\n### .array_delete\n\n def self.array_delete(*values) -\u003e FieldValue\n\nCreates a sentinel value to indicate the removal of the given values\nwith an array. \n**Parameter**\n\n- **values** (Object) --- The values to remove from the array. Required. \n**Returns**\n\n- ([FieldValue](./Google-Cloud-Firestore-FieldValue)) --- The array delete field value object. \n**Raises**\n\n- (ArgumentError)\n**Example** \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Get a document reference\nnyc_ref = firestore.doc \"cities/NYC\"\n\narray_delete = Google::Cloud::Firestore::FieldValue.array_delete(\n 7, 8, 9\n)\n\nnyc_ref.update({ name: \"New York City\",\n lucky_numbers: array_delete })\n```\n\n### .array_union\n\n def self.array_union(*values) -\u003e FieldValue\n\nCreates a sentinel value to indicate the union of the given value\nwith an array. \n**Parameter**\n\n- **values** (Object) --- The values to add to the array. Required. \n**Returns**\n\n- ([FieldValue](./Google-Cloud-Firestore-FieldValue)) --- The array union field value object. \n**Raises**\n\n- (ArgumentError)\n**Example** \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Get a document reference\nnyc_ref = firestore.doc \"cities/NYC\"\n\narray_union = Google::Cloud::Firestore::FieldValue.array_union(\n 1, 2, 3\n)\n\nnyc_ref.update({ name: \"New York City\",\n lucky_numbers: array_union })\n```\n\n### .delete\n\n def self.delete() -\u003e FieldValue\n\nCreates a field value object representing the deletion of a field in\ndocument data. \n**Returns**\n\n- ([FieldValue](./Google-Cloud-Firestore-FieldValue)) --- The delete field value object.\n**Example** \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Get a document reference\nnyc_ref = firestore.doc \"cities/NYC\"\n\nfield_delete = Google::Cloud::Firestore::FieldValue.delete\n\nnyc_ref.update({ name: \"New York City\",\n trash: field_delete })\n```\n\n### .increment\n\n def self.increment(value) -\u003e FieldValue\n\nCreates a sentinel value to indicate the addition the given value to\nthe field's current value.\n\n\n\u003cbr /\u003e\n\nIf the field's current value is not an integer or a double value\n(Numeric), or if the field does not yet exist, the transformation will\nset the field to the given value. If either of the given value or the\ncurrent field value are doubles, both values will be interpreted as\ndoubles. Double arithmetic and representation of double values follow\nIEEE 754 semantics. If there is positive/negative integer overflow,\nthe field is resolved to the largest magnitude positive/negative\ninteger. \n**Parameter**\n\n- **value** (Numeric) --- The value to add to the given value. Required. \n**Returns**\n\n- ([FieldValue](./Google-Cloud-Firestore-FieldValue)) --- The increment field value object. \n**Raises**\n\n- (ArgumentError) --- if the value is not an Integer or Numeric.\n**Example** \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Get a document reference\nnyc_ref = firestore.doc \"cities/NYC\"\n\n# Set the population to increment by 1.\nincrement_value = Google::Cloud::Firestore::FieldValue.increment 1\n\nnyc_ref.update({ name: \"New York City\",\n population: increment_value })\n```\n\n### .maximum\n\n def self.maximum(value) -\u003e FieldValue\n\nCreates a sentinel value to indicate the setting the field to the\nmaximum of its current value and the given value.\n\n\n\u003cbr /\u003e\n\nIf the field is not an integer or double (Numeric), or if the field\ndoes not yet exist, the transformation will set the field to the given\nvalue. If a maximum operation is applied where the field and the input\nvalue are of mixed types (that is - one is an integer and one is a\ndouble) the field takes on the type of the larger operand. If the\noperands are equivalent (e.g. 3 and 3.0), the field does not change.\n0, 0.0, and -0.0 are all zero. The maximum of a zero stored value and\nzero input value is always the stored value. The maximum of any\nnumeric value x and NaN is NaN. \n**Parameter**\n\n- **value** (Numeric) --- The value to compare against the given value to calculate the maximum value to set. Required. \n**Returns**\n\n- ([FieldValue](./Google-Cloud-Firestore-FieldValue)) --- The maximum field value object. \n**Raises**\n\n- (ArgumentError) --- if the value is not an Integer or Numeric.\n**Example** \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Get a document reference\nnyc_ref = firestore.doc \"cities/NYC\"\n\n# Set the population to be at maximum 4,000,000.\nmaximum_value = Google::Cloud::Firestore::FieldValue.maximum 4000000\n\nnyc_ref.update({ name: \"New York City\",\n population: maximum_value })\n```\n\n### .minimum\n\n def self.minimum(value) -\u003e FieldValue\n\nCreates a sentinel value to indicate the setting the field to the\nminimum of its current value and the given value.\n\n\n\u003cbr /\u003e\n\nIf the field is not an integer or double (Numeric), or if the field\ndoes not yet exist, the transformation will set the field to the input\nvalue. If a minimum operation is applied where the field and the input\nvalue are of mixed types (that is - one is an integer and one is a\ndouble) the field takes on the type of the smaller operand. If the\noperands are equivalent (e.g. 3 and 3.0), the field does not change.\n0, 0.0, and -0.0 are all zero. The minimum of a zero stored value and\nzero input value is always the stored value. The minimum of any\nnumeric value x and NaN is NaN. \n**Parameter**\n\n- **value** (Numeric) --- The value to compare against the given value to calculate the minimum value to set. Required. \n**Returns**\n\n- ([FieldValue](./Google-Cloud-Firestore-FieldValue)) --- The minimum field value object. \n**Raises**\n\n- (ArgumentError) --- if the value is not an Integer or Numeric.\n**Example** \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Get a document reference\nnyc_ref = firestore.doc \"cities/NYC\"\n\n# Set the population to be at minimum 1,000,000.\nminimum_value = Google::Cloud::Firestore::FieldValue.minimum 1000000\n\nnyc_ref.update({ name: \"New York City\",\n population: minimum_value })\n```\n\n### .server_time\n\n def self.server_time() -\u003e FieldValue\n\nCreates a field value object representing set a field's value to\nthe server timestamp when accessing the document data. \n**Returns**\n\n- ([FieldValue](./Google-Cloud-Firestore-FieldValue)) --- The server time field value object.\n**Example** \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Get a document reference\nnyc_ref = firestore.doc \"cities/NYC\"\n\nfield_server_time = Google::Cloud::Firestore::FieldValue.server_time\n\nnyc_ref.update({ name: \"New York City\",\n updated_at: field_server_time })\n```\n\n### #type\n\n def type() -\u003e Symbol\n\nThe type of change to make to an individual field in document data. \n**Returns**\n\n- (Symbol) --- The type.\n**Example** \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Get a document reference\nnyc_ref = firestore.doc \"cities/NYC\"\n\nfield_delete = Google::Cloud::Firestore::FieldValue.delete\nfield_delete.type #=\u003e :delete\n\nnyc_ref.update({ name: \"New York City\",\n trash: field_delete })\n```"]]