firebase::firestore::FieldValue

#include <field_value.h>

A field value represents variant datatypes as stored byFirestore.

Summary

FieldValue can be used when reading a particular field withDocumentSnapshot::Get() or fields withDocumentSnapshot::GetData(). When writing document fields withDocumentReference::Set() orDocumentReference::Update(), it can also represent sentinel values in addition to real data values.

For a non-sentinel instance, you can check whether it is of a particular type with is_foo() and get the value with foo_value(), where foo can be one of null, boolean, integer, double, timestamp, string, blob, reference, geo_point, array or map. If the instance is not of type foo, the call to foo_value() will fail (and cause a crash).

Constructors and Destructors

FieldValue()
Creates an invalidFieldValue that has to be reassigned before it can be used.
FieldValue(constFieldValue & other)
Copy constructor.
FieldValue(FieldValue && other)
Move constructor.
~FieldValue()

Public types

Typeenum
The enumeration of all valid runtime types ofFieldValue.

Friend classes

operator<<
friend std::ostream &
Outputs the string representation of thisFieldValue to the given stream.

Public functions

ToString() const
std::string
Returns a string representation of thisFieldValue for logging/debugging purposes.
array_value() const
std::vector<FieldValue >
Gets the vector of FieldValues contained in thisFieldValue.
blob_size() const
size_t
Gets the blob size contained in thisFieldValue.
blob_value() const
const uint8_t *
Gets the blob value contained in thisFieldValue.
boolean_value() const
bool
Gets the boolean value contained in thisFieldValue.
double_value() const
double
Gets the double value contained in thisFieldValue.
geo_point_value() const
Gets theGeoPoint value contained in thisFieldValue.
integer_value() const
int64_t
Gets the integer value contained in thisFieldValue.
is_array() const
bool
Gets whether thisFieldValue contains an array of FieldValues.
is_blob() const
bool
Gets whether thisFieldValue contains a blob.
is_boolean() const
bool
Gets whether thisFieldValue contains a boolean value.
is_double() const
bool
Gets whether thisFieldValue contains a double value.
is_geo_point() const
bool
Gets whether thisFieldValue contains aGeoPoint.
is_integer() const
bool
Gets whether thisFieldValue contains an integer value.
is_map() const
bool
Gets whether thisFieldValue contains a map of std::string toFieldValue.
is_null() const
bool
Gets whether thisFieldValue is currently null.
is_reference() const
bool
Gets whether thisFieldValue contains a reference to a document in the sameFirestore.
is_string() const
bool
Gets whether thisFieldValue contains a string.
is_timestamp() const
bool
Gets whether thisFieldValue contains a timestamp.
is_valid() const
bool
Returnstrue if thisFieldValue is valid,false if it is not valid.
map_value() const
Gets the map of string toFieldValue contained in thisFieldValue.
operator=(constFieldValue & other)
Copy assignment operator.
operator=(FieldValue && other) noexcept
Move assignment operator.
reference_value() const
Gets theDocumentReference contained in thisFieldValue.
string_value() const
std::string
Gets the string value contained in thisFieldValue.
timestamp_value() const
Gets the timestamp value contained in thisFieldValue.
type() const
Gets the current type contained in thisFieldValue.

Public static functions

Array(std::vector<FieldValue > value)
Constructs aFieldValue containing the givenFieldValue vector value.
ArrayRemove(std::vector<FieldValue > elements)
Returns a special value that can be used with Set() or Update() that tells the server to remove the given elements from any array value that already exists on the server.
ArrayUnion(std::vector<FieldValue > elements)
Returns a special value that can be used with Set() or Update() that tells the server to union the given elements with any array value that already exists on the server.
Blob(const uint8_t *value, size_t size)
Constructs aFieldValue containing the given blob value of given size.
Boolean(bool value)
Constructs aFieldValue containing the given boolean value.
Delete()
Returns a sentinel for use with Update() to mark a field for deletion.
Double(double value)
Constructs aFieldValue containing the given double-precision floating point value.
GeoPoint(GeoPoint value)
Constructs aFieldValue containing the givenGeoPoint value.
Increment(T by_value)
Returns a special value that can be used withSet() orUpdate() that tells the server to increment the field's current value by the given integer value.
Increment(T by_value)
Returns a special value that can be used withSet() orUpdate() that tells the server to increment the field's current value by the given floating point value.
Integer(int64_t value)
Constructs aFieldValue containing the given 64-bit integer value.
Map(MapFieldValue value)
Constructs aFieldValue containing the givenFieldValue map value.
Null()
Constructs a null.
Reference(DocumentReference value)
Constructs aFieldValue containing the given reference value.
ServerTimestamp()
Returns a sentinel that can be used with Set() or Update() to include a server-generated timestamp in the written data.
String(std::string value)
Constructs aFieldValue containing the given std::string value.
Timestamp(Timestamp value)
Constructs aFieldValue containing the givenTimestamp value.

Public types

Type

Type

The enumeration of all valid runtime types ofFieldValue.

Friend classes

operator<<

friendstd::ostream&operator<<(std::ostream&out,constFieldValue&value)

Outputs the string representation of thisFieldValue to the given stream.

See also:ToString() for comments on the representation format.

Public functions

FieldValue

FieldValue()

Creates an invalidFieldValue that has to be reassigned before it can be used.

Calling any member function on an invalidFieldValue will be a no-op. If the function returns a value, it will return a zero, empty, or invalid value, depending on the type of the value.

FieldValue

FieldValue(constFieldValue&other)

Copy constructor.

FieldValue is immutable and can be efficiently copied (no deep copy is performed).

Details
Parameters
other
FieldValue to copy from.

FieldValue

FieldValue(FieldValue&&other)noexcept

Move constructor.

Moving is more efficient than copying for aFieldValue. After being moved from, aFieldValue is equivalent to its default-constructed state.

Details
Parameters
other
FieldValue to move data from.

ToString

std::stringToString()const

array_value

std::vector<FieldValue>array_value()const

Gets the vector of FieldValues contained in thisFieldValue.

blob_size

size_tblob_size()const

Gets the blob size contained in thisFieldValue.

blob_value

constuint8_t*blob_value()const

Gets the blob value contained in thisFieldValue.

boolean_value

boolboolean_value()const

Gets the boolean value contained in thisFieldValue.

double_value

doubledouble_value()const

Gets the double value contained in thisFieldValue.

geo_point_value

classGeoPointgeo_point_value()const

Gets theGeoPoint value contained in thisFieldValue.

integer_value

int64_tinteger_value()const

Gets the integer value contained in thisFieldValue.

is_array

boolis_array()const

Gets whether thisFieldValue contains an array of FieldValues.

is_blob

boolis_blob()const

Gets whether thisFieldValue contains a blob.

is_boolean

boolis_boolean()const

Gets whether thisFieldValue contains a boolean value.

is_double

boolis_double()const

Gets whether thisFieldValue contains a double value.

is_geo_point

boolis_geo_point()const

Gets whether thisFieldValue contains aGeoPoint.

is_integer

boolis_integer()const

Gets whether thisFieldValue contains an integer value.

is_map

boolis_map()const

Gets whether thisFieldValue contains a map of std::string toFieldValue.

is_null

boolis_null()const

Gets whether thisFieldValue is currently null.

is_reference

boolis_reference()const

Gets whether thisFieldValue contains a reference to a document in the sameFirestore.

is_string

boolis_string()const

Gets whether thisFieldValue contains a string.

is_timestamp

boolis_timestamp()const

Gets whether thisFieldValue contains a timestamp.

is_valid

boolis_valid()const

Returnstrue if thisFieldValue is valid,false if it is not valid.

An invalidFieldValue could be the result of:

  • Creating aFieldValue using the default constructor.
  • Moving from theFieldValue.
  • CallingDocumentSnapshot::Get(field) for a field that does not exist in the document.

Details
Returns
true if thisFieldValue is valid,false if thisFieldValue is invalid.

map_value

MapFieldValuemap_value()const

Gets the map of string toFieldValue contained in thisFieldValue.

operator=

FieldValue&operator=(constFieldValue&other)

Copy assignment operator.

FieldValue is immutable and can be efficiently copied (no deep copy is performed).

Details
Parameters
other
FieldValue to copy from.
Returns
Reference to the destinationFieldValue.

operator=

FieldValue&operator=(FieldValue&&other)noexcept

Move assignment operator.

Moving is more efficient than copying for aFieldValue. After being moved from, aFieldValue is equivalent to its default-constructed state.

Details
Parameters
other
FieldValue to move data from.
Returns
Reference to the destinationFieldValue.

reference_value

DocumentReferencereference_value()const

Gets theDocumentReference contained in thisFieldValue.

string_value

std::stringstring_value()const

Gets the string value contained in thisFieldValue.

timestamp_value

classTimestamptimestamp_value()const

Gets the timestamp value contained in thisFieldValue.

type

Typetype()const

Gets the current type contained in thisFieldValue.

~FieldValue

~FieldValue()

Public static functions

Array

FieldValueArray(std::vector<FieldValue>value)

Constructs aFieldValue containing the givenFieldValue vector value.

ArrayRemove

FieldValueArrayRemove(std::vector<FieldValue>elements)

Returns a special value that can be used with Set() or Update() that tells the server 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.

Details
Parameters
elements
The elements to remove from the array.
Returns
TheFieldValue sentinel for use in a call to Set() or Update().

ArrayUnion

FieldValueArrayUnion(std::vector<FieldValue>elements)

Returns a special value that can be used with Set() or Update() that tells the server 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.

Details
Parameters
elements
The elements to union into the array.
Returns
TheFieldValue sentinel for use in a call to Set() or Update().

Blob

FieldValueBlob(constuint8_t*value,size_tsize)

Constructs aFieldValue containing the given blob value of given size.

value is copied into the returnedFieldValue.

Boolean

FieldValueBoolean(boolvalue)

Constructs aFieldValue containing the given boolean value.

Delete

FieldValueDelete()

Returns a sentinel for use with Update() to mark a field for deletion.

Double

FieldValueDouble(doublevalue)

Constructs aFieldValue containing the given double-precision floating point value.

GeoPoint

FieldValueGeoPoint(GeoPointvalue)

Constructs aFieldValue containing the givenGeoPoint value.

Increment

FieldValueIncrement(Tby_value)

Returns a special value that can be used withSet() orUpdate() that tells the server to increment the field's current value by the given integer value.

If the current field value is an integer, possible integer overflows are resolved toLONG_MAX orLONG_MIN. If the current field value is a double, both values will be interpreted as doubles and the arithmetic will follow IEEE 754 semantics.

If field is not an integer or a double, or if the field does not yet exist, the transformation will set the field to the given value.

Details
Parameters
by_value
The integer value to increment by. Should be an integer type not larger thanint64_t.
Returns
TheFieldValue sentinel for use in a call toSet() orUpdate().

Increment

FieldValueIncrement(Tby_value)

Returns a special value that can be used withSet() orUpdate() that tells the server to increment the field's current value by the given floating point value.

If the current field value is an integer, possible integer overflows are resolved toLONG_MAX orLONG_MIN. If the current field value is a double, both values will be interpreted as doubles and the arithmetic will follow IEEE 754 semantics.

If field is not an integer or a double, or if the field does not yet exist, the transformation will set the field to the given value.

Details
Parameters
by_value
The double value to increment by. Should be a floating point type no larger thandouble.
Returns
TheFieldValue sentinel for use in a call toSet() orUpdate().

Integer

FieldValueInteger(int64_tvalue)

Constructs aFieldValue containing the given 64-bit integer value.

Map

FieldValueMap(MapFieldValuevalue)

Constructs aFieldValue containing the givenFieldValue map value.

Null

FieldValueNull()

Constructs a null.

Reference

FieldValueReference(DocumentReferencevalue)

Constructs aFieldValue containing the given reference value.

ServerTimestamp

FieldValueServerTimestamp()

Returns a sentinel that can be used with Set() or Update() to include a server-generated timestamp in the written data.

String

FieldValueString(std::stringvalue)

Constructs aFieldValue containing the given std::string value.

Timestamp

FieldValueTimestamp(Timestampvalue)

Constructs aFieldValue containing the givenTimestamp value.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-01-23 UTC.