DocumentSnapshot

public classDocumentSnapshot

Known direct subclasses
QueryDocumentSnapshot

AQueryDocumentSnapshot contains data read from a document in your Cloud Firestore database as part of a query.


ADocumentSnapshot contains data read from a document in your Cloud Firestore database. The data can be extracted with thegetData orget methods.

If theDocumentSnapshot points to a non-existing document,getData and its corresponding methods will returnnull. You can always explicitly check for a document's existence by callingexists.

Subclassing Note: Cloud 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

Nested types

Controls the return value for server timestamps that have not yet been set to their final value.

Public fields

finalSnapshotMetadata

Public methods

boolean

Returns whether or not the field exists in the document.

boolean

Returns whether or not the field exists in the document.

boolean
boolean
@NullableObject

Returns the value at the field ornull if the field doesn't exist.

@NullableObject
get(@NonNullFieldPath fieldPath)

Returns the value at the field ornull if the field or document doesn't exist.

@NullableObject
get(
    @NonNullString field,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field ornull if the field doesn't exist.

@Nullable T
<T>get(@NonNullString field, @NonNullClass<T> valueType)

Returns the value at the field, converted to a POJO, ornull if the field or document doesn't exist.

@NullableObject
get(
    @NonNullFieldPath fieldPath,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field ornull if the field or document doesn't exist.

@Nullable T
<T>get(@NonNullFieldPath fieldPath, @NonNullClass<T> valueType)

Returns the value at the field, converted to a POJO, ornull if the field or document doesn't exist.

@Nullable T
<T>get(
    @NonNullString field,
    @NonNullClass<T> valueType,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field, converted to a POJO, ornull if the field or document doesn't exist.

@Nullable T
<T>get(
    @NonNullFieldPath fieldPath,
    @NonNullClass<T> valueType,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field, converted to a POJO, ornull if the field or document doesn't exist.

@NullableBlob

Returns the value of the field as a Blob.

@NullableBoolean

Returns the value of the field as a boolean.

@NullableMap<StringObject>

Returns the fields of the document as a Map ornull if the document doesn't exist.

@NullableMap<StringObject>
getData(
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the fields of the document as a Map ornull if the document doesn't exist.

@NullableDate

Returns the value of the field as a Date.

@NullableDate
getDate(
    @NonNullString field,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value of the field as a Date.

@NullableDocumentReference

Returns the value of the field as a DocumentReference.

@NullableDouble

Returns the value of the field as a double.

@NullableGeoPoint

Returns the value of the field as a GeoPoint.

@NonNullString
@NullableLong

Returns the value of the field as a long.

@NonNullSnapshotMetadata
@NonNullDocumentReference

Gets the reference to the document.

@NullableString

Returns the value of the field as a String.

@NullableTimestamp

Returns the value of the field as acom.google.firebase.Timestamp.

@NullableTimestamp
getTimestamp(
    @NonNullString field,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value of the field as acom.google.firebase.Timestamp.

@NullableVectorValue

Returns the value of the field as aVectorValue ornull if the field does not exist in the document.

int
@Nullable T
<T>toObject(@NonNullClass<T> valueType)

Returns the contents of the document converted to a POJO ornull if the document doesn't exist.

@Nullable T
<T>toObject(
    @NonNullClass<T> valueType,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the document converted to a POJO ornull if the document doesn't exist.

@NonNullString

Extension functions

final T
<T extends Object>FirestoreKt.getField(
    @NonNullDocumentSnapshot receiver,
    @NonNullString field
)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

final T
<T extends Object>FirestoreKt.getField(
    @NonNullDocumentSnapshot receiver,
    @NonNullString field,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

final T
<T extends Object>FirestoreKt.getField(
    @NonNullDocumentSnapshot receiver,
    @NonNullFieldPath fieldPath
)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

final T
<T extends Object>FirestoreKt.getField(
    @NonNullDocumentSnapshot receiver,
    @NonNullFieldPath fieldPath,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

final T

Returns the contents of the document converted to a POJO or null if the document doesn't exist.

final T
<T extends Object>FirestoreKt.toObject(
    @NonNullDocumentSnapshot receiver,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the document converted to a POJO or null if the document doesn't exist.

Public fields

metadata

public final SnapshotMetadata metadata

Public methods

contains

public boolean contains(@NonNullString field)

Returns whether or not the field exists in the document. Returns false if the document does not exist.

Parameters
@NonNullString field

the path to the field.

Returns
boolean

true iff the field exists.

contains

public boolean contains(@NonNullFieldPath fieldPath)

Returns whether or not the field exists in the document. Returns false if the document does not exist.

Parameters
@NonNullFieldPath fieldPath

the path to the field.

Returns
boolean

true iff the field exists.

equals

public boolean equals(@NullableObject obj)

exists

public boolean exists()
Returns
boolean

true if the document existed in this snapshot.

get

public @NullableObject get(@NonNullString field)

Returns the value at the field ornull if the field doesn't exist.

Parameters
@NonNullString field

The path to the field

Returns
@NullableObject

The value at the given field ornull.

get

public @NullableObject get(@NonNullFieldPath fieldPath)

Returns the value at the field ornull if the field or document doesn't exist.

Parameters
@NonNullFieldPath fieldPath

The path to the field

Returns
@NullableObject

The value at the given field ornull.

get

public @NullableObject get(
    @NonNullString field,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field ornull if the field doesn't exist.

Parameters
@NonNullString field

The path to the field

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet been set to their final value.

Returns
@NullableObject

The value at the given field ornull.

get

public @Nullable T <T>get(@NonNullString field, @NonNullClass<T> valueType)

Returns the value at the field, converted to a POJO, ornull if the field or document doesn't exist.

Parameters
@NonNullString field

The path to the field

@NonNullClass<T> valueType

The Java class to convert the field value to.

Returns
@Nullable T

The value at the given field ornull.

get

public @NullableObject get(
    @NonNullFieldPath fieldPath,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field ornull if the field or document doesn't exist.

Parameters
@NonNullFieldPath fieldPath

The path to the field

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet been set to their final value.

Returns
@NullableObject

The value at the given field ornull.

get

public @Nullable T <T>get(@NonNullFieldPath fieldPath, @NonNullClass<T> valueType)

Returns the value at the field, converted to a POJO, ornull if the field or document doesn't exist.

Parameters
@NonNullFieldPath fieldPath

The path to the field

@NonNullClass<T> valueType

The Java class to convert the field value to.

Returns
@Nullable T

The value at the given field ornull.

get

public @Nullable T <T>get(
    @NonNullString field,
    @NonNullClass<T> valueType,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field, converted to a POJO, ornull if the field or document doesn't exist.

Parameters
@NonNullString field

The path to the field

@NonNullClass<T> valueType

The Java class to convert the field value to.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet been set to their final value.

Returns
@Nullable T

The value at the given field ornull.

get

public @Nullable T <T>get(
    @NonNullFieldPath fieldPath,
    @NonNullClass<T> valueType,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field, converted to a POJO, ornull if the field or document doesn't exist.

Parameters
@NonNullFieldPath fieldPath

The path to the field

@NonNullClass<T> valueType

The Java class to convert the field value to.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet been set to their final value.

Returns
@Nullable T

The value at the given field ornull.

getBlob

public @NullableBlob getBlob(@NonNullString field)

Returns the value of the field as a Blob.

Parameters
@NonNullString field

The path to the field.

Returns
@NullableBlob

The value of the field

Throws
java.lang.RuntimeException java.lang.RuntimeException

if the value is not a Blob.

getBoolean

public @NullableBoolean getBoolean(@NonNullString field)

Returns the value of the field as a boolean. If the value is not a boolean this will throw a runtime exception.

Parameters
@NonNullString field

The path to the field.

Returns
@NullableBoolean

The value of the field

getData

public @NullableMap<StringObjectgetData()

Returns the fields of the document as a Map ornull if the document doesn't exist. Field values will be converted to their native Java representation.

Returns
@NullableMap<StringObject>

The fields of the document as a Map ornull if the document doesn't exist.

getData

public @NullableMap<StringObjectgetData(
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the fields of the document as a Map ornull if the document doesn't exist. Field values will be converted to their native Java representation.

Parameters
@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet been set to their final value.

Returns
@NullableMap<StringObject>

The fields of the document as a Map ornull if the document doesn't exist.

getDate

public @NullableDate getDate(@NonNullString field)

Returns the value of the field as a Date.

Parameters
@NonNullString field

The path to the field.

Returns
@NullableDate

The value of the field

Throws
java.lang.RuntimeException java.lang.RuntimeException

if the value is not a Date.

getDate

public @NullableDate getDate(
    @NonNullString field,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value of the field as a Date.

Parameters
@NonNullString field

The path to the field.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet been set to their final value.

Returns
@NullableDate

The value of the field

Throws
java.lang.RuntimeException java.lang.RuntimeException

if the value is not a Date.

getDocumentReference

public @NullableDocumentReference getDocumentReference(@NonNullString field)

Returns the value of the field as a DocumentReference.

Parameters
@NonNullString field

The path to the field.

Returns
@NullableDocumentReference

The value of the field

Throws
java.lang.RuntimeException java.lang.RuntimeException

if the value is not a DocumentReference.

getDouble

public @NullableDouble getDouble(@NonNullString field)

Returns the value of the field as a double.

Parameters
@NonNullString field

The path to the field.

Returns
@NullableDouble

The value of the field

Throws
java.lang.RuntimeException java.lang.RuntimeException

if the value is not a number.

getGeoPoint

public @NullableGeoPoint getGeoPoint(@NonNullString field)

Returns the value of the field as a GeoPoint.

Parameters
@NonNullString field

The path to the field.

Returns
@NullableGeoPoint

The value of the field

Throws
java.lang.RuntimeException java.lang.RuntimeException

if the value is not a GeoPoint.

getId

public @NonNullString getId()
Returns
@NonNullString

The id of the document.

getLong

public @NullableLong getLong(@NonNullString field)

Returns the value of the field as a long.

Parameters
@NonNullString field

The path to the field.

Returns
@NullableLong

The value of the field

Throws
java.lang.RuntimeException java.lang.RuntimeException

if the value is not a number.

getMetadata

public @NonNullSnapshotMetadata getMetadata()
Returns
@NonNullSnapshotMetadata

The metadata for this document snapshot.

getReference

public @NonNullDocumentReference getReference()

Gets the reference to the document.

Returns
@NonNullDocumentReference

The reference to the document.

getString

public @NullableString getString(@NonNullString field)

Returns the value of the field as a String.

Parameters
@NonNullString field

The path to the field.

Returns
@NullableString

The value of the field

Throws
java.lang.RuntimeException java.lang.RuntimeException

if the value is not a String.

getTimestamp

public @NullableTimestamp getTimestamp(@NonNullString field)

Returns the value of the field as acom.google.firebase.Timestamp.

Parameters
@NonNullString field

The path to the field.

Returns
@NullableTimestamp

The value of the field

Throws
java.lang.RuntimeException java.lang.RuntimeException

if this is not a timestamp field.

getTimestamp

public @NullableTimestamp getTimestamp(
    @NonNullString field,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value of the field as acom.google.firebase.Timestamp.

Parameters
@NonNullString field

The path to the field.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet been set to their final value.

Returns
@NullableTimestamp

The value of the field

Throws
java.lang.RuntimeException java.lang.RuntimeException

if the value is not a timestamp field.

getVectorValue

public @NullableVectorValue getVectorValue(@NonNullString field)

Returns the value of the field as aVectorValue ornull if the field does not exist in the document.

Parameters
@NonNullString field

The path to the field.

Returns
@NullableVectorValue

The value of the field.

Throws
java.lang.RuntimeException java.lang.RuntimeException

if the value is not aVectorValue.

hashCode

public int hashCode()

toObject

public @Nullable T <T>toObject(@NonNullClass<T> valueType)

Returns the contents of the document converted to a POJO ornull if the document doesn't exist.

Parameters
@NonNullClass<T> valueType

The Java class to create

Returns
@Nullable T

The contents of the document in an object of type T ornull if the document doesn't exist.

toObject

public @Nullable T <T>toObject(
    @NonNullClass<T> valueType,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the document converted to a POJO ornull if the document doesn't exist.

Parameters
@NonNullClass<T> valueType

The Java class to create

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet been set to their final value.

Returns
@Nullable T

The contents of the document in an object of type T ornull if the document doesn't exist.

toString

public @NonNullString toString()

Extension functions

FirestoreKt.getField

public final T <T extends Object>FirestoreKt.getField(
    @NonNullDocumentSnapshot receiver,
    @NonNullString field
)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

Parameters
<T extends Object>

The type to convert the field value to.

@NonNullString field

The path to the field.

Returns
T

The value at the given field or null.

FirestoreKt.getField

public final T <T extends Object>FirestoreKt.getField(
    @NonNullDocumentSnapshot receiver,
    @NonNullString field,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

Parameters
<T extends Object>

The type to convert the field value to.

@NonNullString field

The path to the field.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet

beensettotheirfinalvalue.
@return

The value at the given field or null.

FirestoreKt.getField

public final T <T extends Object>FirestoreKt.getField(
    @NonNullDocumentSnapshot receiver,
    @NonNullFieldPath fieldPath
)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

Parameters
<T extends Object>

The type to convert the field value to.

@NonNullFieldPath fieldPath

The path to the field.

Returns
T

The value at the given field or null.

FirestoreKt.getField

public final T <T extends Object>FirestoreKt.getField(
    @NonNullDocumentSnapshot receiver,
    @NonNullFieldPath fieldPath,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

Parameters
<T extends Object>

The type to convert the field value to.

@NonNullFieldPath fieldPath

The path to the field.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet

beensettotheirfinalvalue.
@return

The value at the given field or null.

FirestoreKt.toObject

public final T <T extends Object>FirestoreKt.toObject(@NonNullDocumentSnapshot receiver)

Returns the contents of the document converted to a POJO or null if the document doesn't exist.

Parameters
<T extends Object>

The type of the object to create.

Returns
T

The contents of the document in an object of type T or null if the document doesn't

    exist.

FirestoreKt.toObject

public final T <T extends Object>FirestoreKt.toObject(
    @NonNullDocumentSnapshot receiver,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the document converted to a POJO or null if the document doesn't exist.

Parameters
<T extends Object>

The type of the object to create.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet

beensettotheirfinalvalue.
@return

The contents of the document in an object of type T or null if the document doesn't

    exist.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-01-15 UTC.