java.lang.Object |
↳ |
com.google.firebase.firestore.DocumentSnapshot |
Known Direct Subclasses
QueryDocumentSnapshot |
A QueryDocumentSnapshot contains data read from a document in your Firestore database as part of
a query. |
|
Class Overview
A DocumentSnapshot contains data read from a document in your Firestore database. The data can be
extracted with the getData() or get() 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.
Summary
Public Methods |
boolean
|
contains(String field)
Returns whether or not the field exists in the document.
|
boolean
|
contains(FieldPath fieldPath)
Returns whether or not the field exists in the document.
|
boolean
|
equals(Object obj)
|
boolean
|
exists()
|
Object
|
get(FieldPath fieldPath)
Returns the value at the field or null if the field doesn't exist.
|
Object
|
get(String field)
Returns the value at the field or null if the field doesn't exist.
|
Blob
|
getBlob(String field)
Returns the value of the field as a Blob.
|
Boolean
|
getBoolean(String field)
Returns the value of the field as a boolean.
|
Map<String, Object>
|
getData()
Returns the fields of the document as a Map or null if the document doesn't exist.
|
Date
|
getDate(String field)
Returns the value of the field as a Date.
|
DocumentReference
|
getDocumentReference(String field)
Returns the value of the field as a DocumentReference.
|
Double
|
getDouble(String field)
Returns the value of the field as a double.
|
GeoPoint
|
getGeoPoint(String field)
Returns the value of the field as a GeoPoint.
|
String
|
getId()
|
Long
|
getLong(String field)
Returns the value of the field as a long.
|
SnapshotMetadata
|
getMetadata()
|
DocumentReference
|
getReference()
Gets the reference to the document.
|
String
|
getString(String field)
Returns the value of the field as a String.
|
int
|
hashCode()
|
<T>
T
|
toObject(Class<T> valueType)
Returns the contents of the document converted to a POJO or null if the document doesn't exist.
|
[Expand]
Inherited Methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public Methods
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 |
String : the path to the field. |
Returns |
boolean |
true iff the field exists.
|
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 |
FieldPath : the path to the field. |
Returns |
boolean |
true iff the field exists.
|
public
boolean
equals
(Object obj)
public
boolean
exists
()
Returns |
boolean |
true if the document existed in this snapshot. |
public
Object
get
(FieldPath fieldPath)
Returns the value at the field or null if the field doesn't exist.
Parameters |
fieldPath |
FieldPath : The path to the field |
Returns |
Object |
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 |
String : The path to the field |
Returns |
Object |
The value at the given field or null.
|
public
Blob
getBlob
(String field)
Returns the value of the field as a Blob. If the value is not a Blob this will throw a runtime
exception.
Parameters |
field |
String : The path to the field. |
Returns |
Blob |
The value of the field
|
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 |
String : The path to the field. |
Returns |
Boolean |
The value of the field
|
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 |
Map<String, Object> |
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. If the value is not a Date this will throw a runtime
exception.
Parameters |
field |
String : The path to the field. |
Returns |
Date |
The value of the field
|
public
DocumentReference
getDocumentReference
(String field)
Returns the value of the field as a DocumentReference. If the value is not a DocumentReference
this will throw a runtime exception.
Parameters |
field |
String : The path to the field. |
public
Double
getDouble
(String field)
Returns the value of the field as a double. If the value is not a double this will throw a
runtime exception.
Parameters |
field |
String : The path to the field. |
Returns |
Double |
The value of the field
|
public
GeoPoint
getGeoPoint
(String field)
Returns the value of the field as a GeoPoint. If the value is not a GeoPoint this will throw a
runtime exception.
Parameters |
field |
String : The path to the field. |
public
String
getId
()
Returns |
String |
The id of the document. |
public
Long
getLong
(String field)
Returns the value of the field as a long. If the value is not a long this will throw a runtime
exception.
Parameters |
field |
String : The path to the field. |
Returns |
Long |
The value of the field
|
Gets the reference to the document.
public
String
getString
(String field)
Returns the value of the field as a String. If the value is not a String this will throw a
runtime exception.
Parameters |
field |
String : The path to the field. |
Returns |
String |
The value of the field
|
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 |
Class : The Java class to create |
Returns |
T |
The contents of the document in an object of type T or null if the document doesn't
exist.
|