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 | |
|---|---|
Type | enum The enumeration of all valid runtime types ofFieldValue. |
Friend classes | |
|---|---|
operator<< | friend std::ostream &Outputs the string representation of this FieldValue to the given stream. |
Public functions | |
|---|---|
ToString() const | std::stringReturns a string representation of this FieldValue for logging/debugging purposes. |
array_value() const | std::vector<FieldValue >Gets the vector of FieldValues contained in thisFieldValue. |
blob_size() const | size_tGets the blob size contained in thisFieldValue. |
blob_value() const | const uint8_t *Gets the blob value contained in thisFieldValue. |
boolean_value() const | boolGets the boolean value contained in thisFieldValue. |
double_value() const | doubleGets the double value contained in thisFieldValue. |
geo_point_value() const | classGeoPointGets theGeoPoint value contained in thisFieldValue. |
integer_value() const | int64_tGets the integer value contained in thisFieldValue. |
is_array() const | boolGets whether thisFieldValue contains an array of FieldValues. |
is_blob() const | boolGets whether thisFieldValue contains a blob. |
is_boolean() const | boolGets whether thisFieldValue contains a boolean value. |
is_double() const | boolGets whether thisFieldValue contains a double value. |
is_geo_point() const | boolGets whether thisFieldValue contains aGeoPoint. |
is_integer() const | boolGets whether thisFieldValue contains an integer value. |
is_map() const | boolGets whether thisFieldValue contains a map of std::string toFieldValue. |
is_null() const | boolGets whether thisFieldValue is currently null. |
is_reference() const | boolGets whether thisFieldValue contains a reference to a document in the sameFirestore. |
is_string() const | boolGets whether thisFieldValue contains a string. |
is_timestamp() const | boolGets whether thisFieldValue contains a timestamp. |
is_valid() const | bool |
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::stringGets the string value contained in thisFieldValue. |
timestamp_value() const | classTimestampGets 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 with Set() 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 with Set() 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
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 |
|
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 |
|
ToString
std::stringToString()const
Returns a string representation of thisFieldValue for logging/debugging purposes.
array_value
std::vector<FieldValue>array_value()const
Gets the vector of FieldValues contained in thisFieldValue.
geo_point_value
classGeoPointgeo_point_value()const
Gets theGeoPoint value contained in thisFieldValue.
is_reference
boolis_reference()const
Gets whether thisFieldValue contains a reference to a document in the sameFirestore.
is_valid
boolis_valid()const
Returnstrue if thisFieldValue is valid,false if it is not valid.
An invalidFieldValue could be the result of:
- Creating a
FieldValueusing the default constructor. - Moving from the
FieldValue. - Calling
DocumentSnapshot::Get(field)for a field that does not exist in the document.
| Details | |
|---|---|
| Returns |
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 |
| ||
| Returns | Reference to the destination FieldValue. |
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 |
| ||
| Returns | Reference to the destination FieldValue. |
reference_value
DocumentReferencereference_value()const
Gets theDocumentReference contained in thisFieldValue.
timestamp_value
classTimestamptimestamp_value()const
Gets the timestamp value 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 |
| ||
| 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 |
| ||
| 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.
Double
FieldValueDouble(doublevalue)
Constructs aFieldValue containing the given double-precision floating point 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 |
| ||
| Returns |
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 |
| ||
| Returns |
Integer
FieldValueInteger(int64_tvalue)
Constructs aFieldValue containing the given 64-bit integer value.
Map
FieldValueMap(MapFieldValuevalue)
Constructs aFieldValue containing the givenFieldValue map value.
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.