Class DocumentSnapshot (3.30.2)

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
Name Description
fieldPath FieldPath

The path to the field

valueType Class<T>

The Java class to convert the field value to.

Returns
Type Description
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
Name Description
field String

The path to the field

valueType Class<T>

The Java class to convert the field value to.

Returns
Type Description
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
Name Description
valueType Class<T>

The Java class to create

Returns
Type Description
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
Name Description
fieldPath FieldPath

the path to the field.

Returns
Type Description
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
Name Description
field String

the path to the field.

Returns
Type Description
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
Name Description
obj Object

The object to compare against.

Returns
Type Description
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
Type Description
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
Name Description
fieldPath FieldPath

The path to the field.

Returns
Type Description
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
Name Description
field String

The path to the field.

Returns
Type Description
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
Name Description
field String

The path to the field.

Returns
Type Description
Blob

The value of the field.

getBoolean(String field)

public Boolean getBoolean(String field)

Returns the value of the field as a boolean.

Parameter
Name Description
field String

The path to the field.

Returns
Type Description
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
Type Description
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
Type Description
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
Name Description
field String

The path to the field.

Returns
Type Description
Date

The value of the field.

getDouble(String field)

public Double getDouble(String field)

Returns the value of the field as a double.

Parameter
Name Description
field String

The path to the field.

Returns
Type Description
Double

The value of the field.

getGeoPoint(String field)

public GeoPoint getGeoPoint(String field)

Returns the value of the field as a GeoPoint.

Parameter
Name Description
field String

The path to the field.

Returns
Type Description
GeoPoint

The value of the field.

getId()

public String getId()

Returns the ID of the document contained in this snapshot.

Returns
Type Description
String

The id of the document.

getLong(String field)

public Long getLong(String field)

Returns the value of the field as a long.

Parameter
Name Description
field String

The path to the field.

Returns
Type Description
Long

The value of the field.

getReadTime()

public Timestamp getReadTime()

Returns the time at which this snapshot was read.

Returns
Type Description
com.google.cloud.Timestamp

The read time of this snapshot.

getReference()

public DocumentReference getReference()

Gets the reference to the document.

Returns
Type Description
DocumentReference

The reference to the document.

getString(String field)

public String getString(String field)

Returns the value of the field as a String.

Parameter
Name Description
field String

The path to the field.

Returns
Type Description
String

The value of the field.

getTimestamp(String field)

public Timestamp getTimestamp(String field)

Returns the value of the field as a Timestamp.

Parameter
Name Description
field String

The path to the field.

Returns
Type Description
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
Type Description
com.google.cloud.Timestamp

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

getVectorValue(String field)

public VectorValue getVectorValue(String field)

Returns the value of the field as a VectorValue.

Parameter
Name Description
field String

The path to the field.

Returns
Type Description
VectorValue

The value of the field.

hashCode()

public int hashCode()
Returns
Type Description
int
Overrides

toString()

public String toString()
Returns
Type Description
String
Overrides