Class DocumentSnapshot (3.9.6)

public class DocumentSnapshot

A DocumentSnapshot contains data read from a document in a Firestore database. The data can be extracted with the #getData() or #get(String) methods.

If the DocumentSnapshot points to a non-existing document, getData() and its corresponding methods will return null. You can always explicitly check for a document's existence by calling #exists().

Subclassing Note: Firestore classes are not meant to be subclassed except for use in test mocks. Subclassing is not supported in production code and new SDK releases may break code that does so.

Inheritance

Object > DocumentSnapshot

Methods

<T>get(FieldPath fieldPath, Class<T> valueType)

public T <T>get(FieldPath fieldPath, Class<T> valueType)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

Parameters
NameDescription
fieldPathFieldPath

The path to the field

valueTypeClass<T>

The Java class to convert the field value to.

Returns
TypeDescription
T

The value at the given field or null.

<T>get(String field, Class<T> valueType)

public T <T>get(String field, Class<T> valueType)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

Parameters
NameDescription
fieldString

The path to the field

valueTypeClass<T>

The Java class to convert the field value to.

Returns
TypeDescription
T

The value at the given field or null.

<T>toObject(Class<T> valueType)

public T <T>toObject(Class<T> valueType)

Returns the contents of the document converted to a POJO or null if the document doesn't exist.

Parameter
NameDescription
valueTypeClass<T>

The Java class to create

Returns
TypeDescription
T

The contents of the document in an object of type T or null if the document doesn't exist.

contains(FieldPath fieldPath)

public boolean contains(FieldPath fieldPath)

Returns whether or not the field exists in the document. Returns false if the document does not exist.

Parameter
NameDescription
fieldPathFieldPath

the path to the field.

Returns
TypeDescription
boolean

true iff the field exists.

contains(String field)

public boolean contains(String field)

Returns whether or not the field exists in the document. Returns false if the document does not exist.

Parameter
NameDescription
fieldString

the path to the field.

Returns
TypeDescription
boolean

true iff the field exists.

equals(Object obj)

public boolean equals(Object obj)

Returns true if the document's data and path in this DocumentSnapshot equals the provided snapshot.

Parameter
NameDescription
objObject

The object to compare against.

Returns
TypeDescription
boolean

Whether this DocumentSnapshot is equal to the provided object.

Overrides

exists()

public boolean exists()

Returns whether or not the field exists in the document. Returns false if the document does not exist.

Returns
TypeDescription
boolean

whether the document existed in this snapshot.

get(FieldPath fieldPath)

public Object get(FieldPath fieldPath)

Returns the value at the field or null if the field doesn't exist.

Parameter
NameDescription
fieldPathFieldPath

The path to the field.

Returns
TypeDescription
Object

The value at the given field or null.

get(String field)

public Object get(String field)

Returns the value at the field or null if the field doesn't exist.

Parameter
NameDescription
fieldString

The path to the field.

Returns
TypeDescription
Object

The value at the given field or null.

getBlob(String field)

public Blob getBlob(String field)

Returns the value of the field as a Blob.

Parameter
NameDescription
fieldString

The path to the field.

Returns
TypeDescription
Blob

The value of the field.

getBoolean(String field)

public Boolean getBoolean(String field)

Returns the value of the field as a boolean.

Parameter
NameDescription
fieldString

The path to the field.

Returns
TypeDescription
Boolean

The value of the field.

getCreateTime()

public Timestamp getCreateTime()

Returns the time at which this document was created. Returns null for non-existing documents.

Returns
TypeDescription
com.google.cloud.Timestamp

The last time the document in the snapshot was created. Null if the document doesn't exist.

getData()

public Map<String,Object> getData()

Returns the fields of the document as a Map or null if the document doesn't exist. Field values will be converted to their native Java representation.

Returns
TypeDescription
Map<String,Object>

The fields of the document as a Map or null if the document doesn't exist.

getDate(String field)

public Date getDate(String field)

Returns the value of the field as a Date.

Parameter
NameDescription
fieldString

The path to the field.

Returns
TypeDescription
Date

The value of the field.

getDouble(String field)

public Double getDouble(String field)

Returns the value of the field as a double.

Parameter
NameDescription
fieldString

The path to the field.

Returns
TypeDescription
Double

The value of the field.

getGeoPoint(String field)

public GeoPoint getGeoPoint(String field)

Returns the value of the field as a GeoPoint.

Parameter
NameDescription
fieldString

The path to the field.

Returns
TypeDescription
GeoPoint

The value of the field.

getId()

public String getId()

Returns the ID of the document contained in this snapshot.

Returns
TypeDescription
String

The id of the document.

getLong(String field)

public Long getLong(String field)

Returns the value of the field as a long.

Parameter
NameDescription
fieldString

The path to the field.

Returns
TypeDescription
Long

The value of the field.

getReadTime()

public Timestamp getReadTime()

Returns the time at which this snapshot was read.

Returns
TypeDescription
com.google.cloud.Timestamp

The read time of this snapshot.

getReference()

public DocumentReference getReference()

Gets the reference to the document.

Returns
TypeDescription
DocumentReference

The reference to the document.

getString(String field)

public String getString(String field)

Returns the value of the field as a String.

Parameter
NameDescription
fieldString

The path to the field.

Returns
TypeDescription
String

The value of the field.

getTimestamp(String field)

public Timestamp getTimestamp(String field)

Returns the value of the field as a Timestamp.

Parameter
NameDescription
fieldString

The path to the field.

Returns
TypeDescription
com.google.cloud.Timestamp

The value of the field.

getUpdateTime()

public Timestamp getUpdateTime()

Returns the time at which this document was last updated. Returns null for non-existing documents.

Returns
TypeDescription
com.google.cloud.Timestamp

The last time the document in the snapshot was updated. Null if the document doesn't exist.

hashCode()

public int hashCode()
Returns
TypeDescription
int
Overrides