DocumentSnapshot | Doclava
public class

DocumentSnapshot

extends Object
java.lang.Object
   ↳ com.google.firebase.firestore.DocumentSnapshot
Known Direct Subclasses

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

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)

Parameters
obj Object
Returns
boolean

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.
Returns
DocumentReference The value of 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.
Returns
GeoPoint The value of 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

public SnapshotMetadata getMetadata ()

Returns
SnapshotMetadata The metadata for this document snapshot.

public DocumentReference getReference ()

Gets the reference to the document.

Returns
DocumentReference 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 int hashCode ()

Returns
int

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.