Known Direct Subclasses |
A DocumentSnapshot
contains data read from a document in your Cloud 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: Cloud 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.
Nested Class Summary
enum | DocumentSnapshot.ServerTimestampBehavior | Controls the return value for server timestamps that have not yet been set to their final value. |
Public Method Summary
boolean | |
boolean | |
boolean | |
boolean |
exists()
|
<T> T |
get(FieldPath
fieldPath, Class<T>
valueType,
DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value at the field, converted to a POJO, or
null if
the field or document doesn't exist.
|
<T> T |
get(String field,
Class<T>
valueType,
DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value at the field, converted to a POJO, or
null if
the field or document doesn't exist.
|
Object |
get(String field,
DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value at the field or
null if the field doesn't exist.
|
Object | |
Object |
get(FieldPath
fieldPath,
DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value at the field or
null if the field or document
doesn't exist.
|
<T> T | |
<T> T | |
Object | |
Blob | |
Boolean | |
Map<String, Object> |
getData(DocumentSnapshot.ServerTimestampBehavior
serverTimestampBehavior)
Returns the fields of the document as a Map or
null if the
document doesn't exist.
|
Map<String, Object> |
getData()
Returns the fields of the document as a Map or
null if the
document doesn't exist.
|
Date | |
Date |
getDate(String field,
DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value of the field as a Date.
|
DocumentReference | |
Double | |
GeoPoint | |
String |
getId()
|
Long | |
SnapshotMetadata | |
DocumentReference |
getReference()
Gets the reference to the document.
|
String | |
Timestamp |
getTimestamp(String field,
DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value of the field as a
com.google.firebase.Timestamp .
|
Timestamp | |
int |
hashCode()
|
<T> T | |
<T> T |
toObject(Class<T>
valueType,
DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the contents of the document converted to a POJO or
null
if the document doesn't exist.
|
String |
toString()
|
Inherited Method Summary
Public Methods
public boolean contains (FieldPath fieldPath)
Returns whether or not the field exists in the document. Returns false if the document does not exist.
Parameters
fieldPath | the path to the field. |
---|
Returns
- true iff the field exists.
public boolean contains (String field)
Returns whether or not the field exists in the document. Returns false if the document does not exist.
Parameters
field | the path to the field. |
---|
Returns
- true iff the field exists.
public boolean equals (Object obj)
public boolean exists ()
Returns
- true if the document existed in this snapshot.
public T get (FieldPath fieldPath, Class<T> valueType, DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value at the field, converted to a POJO, or null
if the
field or document doesn't exist.
Parameters
fieldPath | The path to the field |
---|---|
valueType | The Java class to convert the field value to. |
serverTimestampBehavior | Configures the behavior for server timestamps that have not yet been set to their final value. |
Returns
- The value at the given field or
null
.
public T get (String field, Class<T> valueType, DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value at the field, converted to a POJO, or null
if the
field or document doesn't exist.
Parameters
field | The path to the field |
---|---|
valueType | The Java class to convert the field value to. |
serverTimestampBehavior | Configures the behavior for server timestamps that have not yet been set to their final value. |
Returns
- The value at the given field or
null
.
public Object get (String field, DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value at the field or null
if the field doesn't exist.
Parameters
field | The path to the field |
---|---|
serverTimestampBehavior | Configures the behavior for server timestamps that have not yet been set to their final value. |
Returns
- The value at the given field or
null
.
public Object get (FieldPath fieldPath)
Returns the value at the field or null
if the field or document doesn't
exist.
Parameters
fieldPath | The path to the field |
---|
Returns
- The value at the given field or
null
.
public Object get (FieldPath fieldPath, DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value at the field or null
if the field or document doesn't
exist.
Parameters
fieldPath | The path to the field |
---|---|
serverTimestampBehavior | Configures the behavior for server timestamps that have not yet been set to their final value. |
Returns
- The value at the given field or
null
.
public 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
fieldPath | The path to the field |
---|---|
valueType | The Java class to convert the field value to. |
Returns
- The value at the given field or
null
.
public 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
field | The path to the field |
---|---|
valueType | The Java class to convert the field value to. |
Returns
- The value at the given field or
null
.
public Object get (String field)
Returns the value at the field or null
if the field doesn't exist.
Parameters
field | The path to the field |
---|
Returns
- The value at the given field or
null
.
public Blob getBlob (String field)
Returns the value of the field as a Blob.
Parameters
field | The path to the field. |
---|
Returns
- The value of the field
Throws
RuntimeException | if the value is not a Blob. |
---|
public Boolean getBoolean (String field)
Returns the value of the field as a boolean. If the value is not a boolean this will throw a runtime exception.
Parameters
field | The path to the field. |
---|
Returns
- The value of the field
public Map<String, Object> getData (DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
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.
Parameters
serverTimestampBehavior | Configures the behavior for server timestamps that have not yet been set to their final value. |
---|
Returns
- The fields of the document as a Map or
null
if the document doesn't exist.
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
- The fields of the document as a Map or
null
if the document doesn't exist.
public Date getDate (String field)
Returns the value of the field as a Date.
Parameters
field | The path to the field. |
---|
Returns
- The value of the field
Throws
RuntimeException | if the value is not a Date. |
---|
public Date getDate (String field, DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value of the field as a Date.
Parameters
field | The path to the field. |
---|---|
serverTimestampBehavior | Configures the behavior for server timestamps that have not yet been set to their final value. |
Returns
- The value of the field
Throws
RuntimeException | if the value is not a Date. |
---|
public DocumentReference getDocumentReference (String field)
Returns the value of the field as a DocumentReference.
Parameters
field | The path to the field. |
---|
Returns
- The value of the field
Throws
RuntimeException | if the value is not a DocumentReference. |
---|
public Double getDouble (String field)
Returns the value of the field as a double.
Parameters
field | The path to the field. |
---|
Returns
- The value of the field
Throws
RuntimeException | if the value is not a number. |
---|
public GeoPoint getGeoPoint (String field)
Returns the value of the field as a GeoPoint.
Parameters
field | The path to the field. |
---|
Returns
- The value of the field
Throws
RuntimeException | if the value is not a GeoPoint. |
---|
public String getId ()
Returns
- The id of the document.
public Long getLong (String field)
Returns the value of the field as a long.
Parameters
field | The path to the field. |
---|
Returns
- The value of the field
Throws
RuntimeException | if the value is not a number. |
---|
public SnapshotMetadata getMetadata ()
Returns
- The metadata for this document snapshot.
public DocumentReference getReference ()
Gets the reference to the document.
Returns
- The reference to the document.
public String getString (String field)
Returns the value of the field as a String.
Parameters
field | The path to the field. |
---|
Returns
- The value of the field
Throws
RuntimeException | if the value is not a String. |
---|
public Timestamp getTimestamp (String field, DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the value of the field as a com.google.firebase.Timestamp
.
Parameters
field | The path to the field. |
---|---|
serverTimestampBehavior | Configures the behavior for server timestamps that have not yet been set to their final value. |
Returns
- The value of the field
Throws
RuntimeException | if the value is not a timestamp field. |
---|
public Timestamp getTimestamp (String field)
Returns the value of the field as a com.google.firebase.Timestamp
.
Parameters
field | The path to the field. |
---|
Returns
- The value of the field
Throws
RuntimeException | if this is not a timestamp field. |
---|
public int hashCode ()
public T toObject (Class<T> valueType)
Returns the contents of the document converted to a POJO or null
if the
document doesn't exist.
Parameters
valueType | The Java class to create |
---|
Returns
- The contents of the document in an object of type T or
null
if the document doesn't exist.
public T toObject (Class<T> valueType, DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior)
Returns the contents of the document converted to a POJO or null
if the
document doesn't exist.
Parameters
valueType | The Java class to create |
---|---|
serverTimestampBehavior | Configures the behavior for server timestamps that have not yet been set to their final value. |
Returns
- The contents of the document in an object of type T or
null
if the document doesn't exist.