Package com.google.cloud.firestore
Class DocumentSnapshot
java.lang.Object
com.google.cloud.firestore.DocumentSnapshot
- Direct Known Subclasses:
QueryDocumentSnapshot
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.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether or not the field exists in the document.booleanReturns whether or not the field exists in the document.booleanReturns true if the document's data and path in this DocumentSnapshot equals the provided snapshot.booleanexists()Returns whether or not the field exists in the document.Returns the value at the field or null if the field doesn't exist.<T> TReturns the value at the field, converted to a POJO, or null if the field or document doesn't exist.Returns the value at the field or null if the field doesn't exist.<T> TReturns the value at the field, converted to a POJO, or null if the field or document doesn't exist.Returns the value of the field as a Blob.getBoolean(String field) Returns the value of the field as a boolean.com.google.cloud.TimestampReturns the time at which this document was created.getData()Returns the fields of the document as a Map or null if the document doesn't exist.Returns the value of the field as a Date.Returns the value of the field as a double.getGeoPoint(String field) Returns the value of the field as a GeoPoint.getId()Returns the ID of the document contained in this snapshot.Returns the value of the field as a long.com.google.cloud.TimestampReturns the time at which this snapshot was read.Gets the reference to the document.Returns the value of the field as a String.com.google.cloud.TimestampgetTimestamp(String field) Returns the value of the field as aTimestamp.com.google.cloud.TimestampReturns the time at which this document was last updated.getVectorValue(String field) Returns the value of the field as a VectorValue.inthashCode()<T> TReturns the contents of the document converted to a POJO or null if the document doesn't exist.toString()
-
Method Details
-
getId
Returns the ID of the document contained in this snapshot.- Returns:
- The id of the document.
-
getReadTime
Returns the time at which this snapshot was read.- Returns:
- The read time of this snapshot.
-
getUpdateTime
Returns the time at which this document was last updated. Returns null for non-existing documents.- Returns:
- The last time the document in the snapshot was updated. Null if the document doesn't exist.
-
getCreateTime
Returns the time at which this document was created. Returns null for non-existing documents.- Returns:
- The last time the document in the snapshot was created. Null if the document doesn't exist.
-
exists
public boolean exists()Returns whether or not the field exists in the document. Returns false if the document does not exist.- Returns:
- whether the document existed in this snapshot.
-
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.
-
toObject
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.
-
contains
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.
-
contains
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.
-
get
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.
-
get
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 fieldvalueType- The Java class to convert the field value to.- Returns:
- The value at the given field or null.
-
get
Returns the value at the field or null if the field doesn't exist.- Parameters:
fieldPath- The path to the field.- Returns:
- The value at the given field or null.
-
get
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 fieldvalueType- The Java class to convert the field value to.- Returns:
- The value at the given field or null.
-
getBoolean
Returns the value of the field as a boolean.- Parameters:
field- The path to the field.- Returns:
- The value of the field.
- Throws:
RuntimeException- if the value is not a Boolean.
-
getDouble
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.
-
getString
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.
-
getLong
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.
-
getDate
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.
-
getTimestamp
Returns the value of the field as aTimestamp.- Parameters:
field- The path to the field.- Returns:
- The value of the field.
- Throws:
RuntimeException- if the value is not a Date.
-
getBlob
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.
-
getGeoPoint
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.
-
getVectorValue
Returns the value of the field as a VectorValue.- Parameters:
field- The path to the field.- Returns:
- The value of the field.
- Throws:
RuntimeException- if the value is not a VectorValue.
-
getReference
Gets the reference to the document.- Returns:
- The reference to the document.
-
equals
Returns true if the document's data and path in this DocumentSnapshot equals the provided snapshot. -
hashCode
public int hashCode() -
toString
-