public class DocumentSnapshot extends Object
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.
Modifier | Constructor and Description |
---|---|
protected |
DocumentSnapshot(com.google.cloud.firestore.FirestoreImpl firestore,
DocumentReference docRef,
Map<String,Value> fields,
com.google.cloud.Timestamp readTime,
com.google.cloud.Timestamp updateTime,
com.google.cloud.Timestamp createTime) |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(FieldPath fieldPath)
Returns whether or not the field exists in the document.
|
boolean |
contains(String field)
Returns whether or not the field exists in the document.
|
boolean |
equals(Object obj)
Returns true if the document's data and path in this DocumentSnapshot equals the provided
snapshot.
|
boolean |
exists()
Returns whether or not the field exists in the document.
|
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.
|
com.google.cloud.Timestamp |
getCreateTime()
Returns the time at which this document was created.
|
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.
|
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()
Returns the ID of the document contained in this snapshot.
|
Long |
getLong(String field)
Returns the value of the field as a long.
|
com.google.cloud.Timestamp |
getReadTime()
Returns the time at which this snapshot was read.
|
DocumentReference |
getReference()
Gets the reference to the document.
|
String |
getString(String field)
Returns the value of the field as a String.
|
com.google.cloud.Timestamp |
getTimestamp(String field)
Returns the value of the field as a
Timestamp . |
com.google.cloud.Timestamp |
getUpdateTime()
Returns the time at which this document was last updated.
|
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.
|
protected DocumentSnapshot(com.google.cloud.firestore.FirestoreImpl firestore, DocumentReference docRef, @Nullable Map<String,Value> fields, @Nullable com.google.cloud.Timestamp readTime, @Nullable com.google.cloud.Timestamp updateTime, @Nullable com.google.cloud.Timestamp createTime)
@Nonnull public String getId()
@Nullable public com.google.cloud.Timestamp getReadTime()
@Nullable public com.google.cloud.Timestamp getUpdateTime()
@Nullable public com.google.cloud.Timestamp getCreateTime()
public boolean exists()
@Nullable public Map<String,Object> getData()
@Nullable public <T> T toObject(@Nonnull Class<T> valueType)
valueType
- The Java class to createpublic boolean contains(@Nonnull String field)
field
- the path to the field.public boolean contains(@Nonnull FieldPath fieldPath)
fieldPath
- the path to the field.@Nullable public Object get(@Nonnull String field)
field
- The path to the field.@Nullable public Object get(@Nonnull FieldPath fieldPath)
fieldPath
- The path to the field.@Nullable public Boolean getBoolean(@Nonnull String field)
field
- The path to the field.RuntimeException
- if the value is not a Boolean.@Nullable public Double getDouble(@Nonnull String field)
field
- The path to the field.RuntimeException
- if the value is not a Number.@Nullable public String getString(@Nonnull String field)
field
- The path to the field.RuntimeException
- if the value is not a String.@Nullable public Long getLong(@Nonnull String field)
field
- The path to the field.RuntimeException
- if the value is not a Number.@Nullable public Date getDate(@Nonnull String field)
This method ignores the global setting FirestoreOptions.areTimestampsInSnapshotsEnabled()
.
field
- The path to the field.RuntimeException
- if the value is not a Date.@Nullable public com.google.cloud.Timestamp getTimestamp(@Nonnull String field)
Timestamp
.
This method ignores the global setting FirestoreOptions.areTimestampsInSnapshotsEnabled()
.
field
- The path to the field.RuntimeException
- if the value is not a Date.@Nullable public Blob getBlob(@Nonnull String field)
field
- The path to the field.RuntimeException
- if the value is not a Blob.@Nullable public GeoPoint getGeoPoint(@Nonnull String field)
field
- The path to the field.RuntimeException
- if the value is not a GeoPoint.@Nonnull public DocumentReference getReference()
public boolean equals(Object obj)
Copyright © 2019 Google LLC. All rights reserved.