DocumentSnapshot | Doclava
public class

DocumentSnapshot

extends Object
java.lang.Object
   ↳ com.google.firebase.firestore.DocumentSnapshot

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.

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 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.
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.
<T> T toObject(Class<T> valueType)
Returns the contents of the document converted to a POJO.
[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.

Parameters
field String:the path to the field.

Returns
boolean true iff the field exists.

Throws
IllegalStateException if the document doesn't exist.

public boolean contains (FieldPath fieldPath)

Returns whether or not the field exists in the document.

Parameters
fieldPath FieldPath:the path to the field.

Returns
boolean true iff the field exists.

Throws
IllegalStateException if the document doesn't exist.

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.

Throws
IllegalStateException if the document doesn't exist.

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.

Throws
IllegalStateException if the document doesn't exist.

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

Throws
IllegalStateException if the document doesn't exist.

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

Throws
IllegalStateException if the document doesn't exist.

public Map<String, Object> getData ()

Returns the fields of the document as a Map. Field values will be converted to their native Java representation.

Returns
Map<String, Object> The fields of the document as a Map.

Throws
IllegalStateException 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

Throws
IllegalStateException if the document doesn't exist.

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

Throws
IllegalStateException if the document doesn't exist.

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

Throws
IllegalStateException if the document doesn't exist.

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

Throws
IllegalStateException if the document doesn't exist.

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

Throws
IllegalStateException if the document doesn't exist.

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

Throws
IllegalStateException if the document doesn't exist.

public T toObject (Class<T> valueType)

Returns the contents of the document converted to a POJO.

Parameters
valueType Class:The Java class to create

Returns
T The contents of the document in an object of type T

Throws
IllegalStateException if the document doesn't exist.