> Documentation index: https://firebase.google.com/docs/reference/llms.txt

# DocumentSnapshot


```
class DocumentSnapshot
```

<br />

Known direct subclasses [QueryDocumentSnapshot](https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/QueryDocumentSnapshot.md.txt)

|---|---|
| `QueryDocumentSnapshot` | A `QueryDocumentSnapshot` contains data read from a document in your Cloud Firestore database as part of a query. |

*** ** * ** ***

A `DocumentSnapshot` contains data read from a document in your Cloud 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**: 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 |
|---|
| `enum DocumentSnapshot.ServerTimestampBehavior` Controls the return value for server timestamps that have not yet been set to their final value. |

| ### Public functions |
|---|---|
| `Boolean` | `contains(field: String)` 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(obj: Any?)` |
| `Boolean` | `exists()` |
| `Any?` | `get(field: String)` Returns the value at the field or `null` if the field doesn't exist. |
| `Any?` | `get(fieldPath: FieldPath)` Returns the value at the field or `null` if the field or document doesn't exist. |
| `Any?` | `get( field: String, serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior )` Returns the value at the field or `null` if the field doesn't exist. |
| `T?` | `<T> get(field: String, valueType: Class<T!>)` Returns the value at the field, converted to a POJO, or `null` if the field or document doesn't exist. |
| `Any?` | `get( fieldPath: FieldPath, serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior )` Returns the value at the field or `null` if the field or document doesn't exist. |
| `T?` | `<T> get(fieldPath: FieldPath, valueType: Class<T!>)` Returns the value at the field, converted to a POJO, or `null` if the field or document doesn't exist. |
| `T?` | `<T> get( field: String, valueType: Class<T!>, serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior )` Returns the value at the field, converted to a POJO, or `null` if the field or document doesn't exist. |
| `T?` | `<T> get( fieldPath: FieldPath, valueType: Class<T!>, serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior )` Returns the value at the field, converted to a POJO, or `null` if the field or document doesn't exist. |
| `Blob?` | `getBlob(field: String)` Returns the value of the field as a `Blob`. |
| `Boolean?` | `getBoolean(field: String)` Returns the value of the field as a boolean. |
| `BsonObjectId?` | `getBsonObjectId(field: String)` Returns the value of the field as a `BsonObjectId`. |
| `BsonTimestamp?` | `getBsonTimestamp(field: String)` Returns the value of the field as a `BsonTimestamp`. |
| `(Mutable)Map<String!, Any!>?` | `getData()` Returns the fields of the document as a Map or `null` if the document doesn't exist. |
| `(Mutable)Map<String!, Any!>?` | `getData( serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior )` Returns the fields of the document as a Map or `null` if the document doesn't exist. |
| `Date?` | `getDate(field: String)` Returns the value of the field as a Date. |
| `Date?` | `getDate( field: String, serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior )` Returns the value of the field as a Date. |
| `Decimal128Value?` | `getDecimal128Value(field: String)` Returns the value of the field as a 128-bit decimal. |
| `DocumentReference?` | `getDocumentReference(field: String)` Returns the value of the field as a DocumentReference. |
| `Double?` | `getDouble(field: String)` Returns the value of the field as a double. |
| `GeoPoint?` | `getGeoPoint(field: String)` Returns the value of the field as a GeoPoint. |
| `String` | `getId()` |
| `Int32Value?` | `getInt32Value(field: String)` Returns the value of the field as a 32-bit integer. |
| `Long?` | `getLong(field: String)` Returns the value of the field as a long. |
| `MaxKey?` | `getMaxKey(field: String)` Returns the value of the field as a `MaxKey`. |
| `MinKey?` | `getMinKey(field: String)` Returns the value of the field as a `MinKey`. |
| `DocumentReference` | `getReference()` Gets the reference to the document. |
| `RegexValue?` | `getRegexValue(field: String)` Returns the value of the field as a `RegexValue`. |
| `String?` | `getString(field: String)` Returns the value of the field as a String. |
| `Timestamp?` | `getTimestamp(field: String)` Returns the value of the field as a `com.google.firebase.Timestamp`. |
| `Timestamp?` | `getTimestamp( field: String, serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior )` Returns the value of the field as a `com.google.firebase.Timestamp`. |
| `VectorValue?` | `getVectorValue(field: String)` Returns the value of the field as a `VectorValue` or `null` if the field does not exist in the document. |
| `Int` | `hashCode()` |
| `T?` | `<T> toObject(valueType: Class<T!>)` Returns the contents of the document converted to a POJO or `null` if the document doesn't exist. |
| `T?` | `<T> toObject( valueType: Class<T!>, serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior )` Returns the contents of the document converted to a POJO or `null` if the document doesn't exist. |
| `String` | `toString()` |

| ### Public properties |
|---|---|
| `SnapshotMetadata!` | `metadata` |

| ### Extension functions |
|---|---|
| `inline T?` | `<T : Any?> DocumentSnapshot.getField(field: String)` Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist. |
| `inline T?` | `<T : Any?> DocumentSnapshot.getField( field: String, serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior )` Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist. |
| `inline T?` | `<T : Any?> DocumentSnapshot.getField(fieldPath: FieldPath)` Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist. |
| `inline T?` | `<T : Any?> DocumentSnapshot.getField( fieldPath: FieldPath, serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior )` Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist. |
| `inline T?` | `<T : Any?> DocumentSnapshot.toObject()` Returns the contents of the document converted to a POJO or null if the document doesn't exist. |
| `inline T?` | `<T : Any?> DocumentSnapshot.toObject( serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior )` Returns the contents of the document converted to a POJO or null if the document doesn't exist. |

## Public functions

### contains

```
fun contains(field: String): Boolean
```

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. |

### contains

```
fun contains(fieldPath: FieldPath): Boolean
```

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. |

### equals

```
fun equals(obj: Any?): Boolean
```

### exists

```
fun exists(): Boolean
```

| Returns |
|---|---|
| `Boolean` | true if the document existed in this snapshot. |

### get

```
fun get(field: String): Any?
```

Returns the value at the field or `null` if the field doesn't exist.

| Parameters |
|---|---|
| `field: String` | The path to the field |

| Returns |
|---|---|
| `Any?` | The value at the given field or `null`. |

### get

```
fun get(fieldPath: FieldPath): Any?
```

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

| Parameters |
|---|---|
| `fieldPath: FieldPath` | The path to the field |

| Returns |
|---|---|
| `Any?` | The value at the given field or `null`. |

### get

```
fun get(
    field: String,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): Any?
```

Returns the value at the field or `null` if the field doesn't exist.

| Parameters |
|---|---|
| `field: String` | The path to the field |
| `serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior` | Configures the behavior for server timestamps that have not yet been set to their final value. |

| Returns |
|---|---|
| `Any?` | The value at the given field or `null`. |

### get

```
fun <T> get(field: String, valueType: Class<T!>): T?
```

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

| Parameters |
|---|---|
| `field: String` | The path to the field |
| `valueType: Class<T!>` | The Java class to convert the field value to. |

| Returns |
|---|---|
| `T?` | The value at the given field or `null`. |

### get

```
fun get(
    fieldPath: FieldPath,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): Any?
```

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

| Parameters |
|---|---|
| `fieldPath: FieldPath` | The path to the field |
| `serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior` | Configures the behavior for server timestamps that have not yet been set to their final value. |

| Returns |
|---|---|
| `Any?` | The value at the given field or `null`. |

### get

```
fun <T> get(fieldPath: FieldPath, valueType: Class<T!>): T?
```

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

| Parameters |
|---|---|
| `fieldPath: FieldPath` | The path to the field |
| `valueType: Class<T!>` | The Java class to convert the field value to. |

| Returns |
|---|---|
| `T?` | The value at the given field or `null`. |

### get

```
fun <T> get(
    field: String,
    valueType: Class<T!>,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): T?
```

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

| Parameters |
|---|---|
| `field: String` | The path to the field |
| `valueType: Class<T!>` | The Java class to convert the field value to. |
| `serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior` | Configures the behavior for server timestamps that have not yet been set to their final value. |

| Returns |
|---|---|
| `T?` | The value at the given field or `null`. |

### get

```
fun <T> get(
    fieldPath: FieldPath,
    valueType: Class<T!>,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): T?
```

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

| Parameters |
|---|---|
| `fieldPath: FieldPath` | The path to the field |
| `valueType: Class<T!>` | The Java class to convert the field value to. |
| `serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior` | Configures the behavior for server timestamps that have not yet been set to their final value. |

| Returns |
|---|---|
| `T?` | The value at the given field or `null`. |

### getBlob

```
fun getBlob(field: String): Blob?
```

Returns the value of the field as a `Blob`.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `Blob?` | The value of the field |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a `Blob`. |

### getBoolean

```
fun getBoolean(field: String): Boolean?
```

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 |

### getBsonObjectId

```
fun getBsonObjectId(field: String): BsonObjectId?
```

Returns the value of the field as a `BsonObjectId`.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `BsonObjectId?` | The value of the field. |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a `BsonObjectId`. |

### getBsonTimestamp

```
fun getBsonTimestamp(field: String): BsonTimestamp?
```

Returns the value of the field as a `BsonTimestamp`.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `BsonTimestamp?` | The value of the field. |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a `BsonTimestamp`. |

### getData

```
fun getData(): (Mutable)Map<String!, Any!>?
```

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 |
|---|---|
| `(Mutable)Map<String!, Any!>?` | The fields of the document as a Map or `null` if the document doesn't exist. |

### getData

```
fun getData(
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): (Mutable)Map<String!, Any!>?
```

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.

| Parameters |
|---|---|
| `serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior` | Configures the behavior for server timestamps that have not yet been set to their final value. |

| Returns |
|---|---|
| `(Mutable)Map<String!, Any!>?` | The fields of the document as a Map or `null` if the document doesn't exist. |

### getDate

```
fun getDate(field: String): Date?
```

Returns the value of the field as a Date.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `Date?` | The value of the field |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a Date. |

### getDate

```
fun getDate(
    field: String,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): Date?
```

Returns the value of the field as a Date.

| Parameters |
|---|---|
| `field: String` | The path to the field. |
| `serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior` | Configures the behavior for server timestamps that have not yet been set to their final value. |

| Returns |
|---|---|
| `Date?` | The value of the field |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a Date. |

### getDecimal128Value

```
fun getDecimal128Value(field: String): Decimal128Value?
```

Returns the value of the field as a 128-bit decimal.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `Decimal128Value?` | The value of the field. |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a `Decimal128Value`. |

### getDocumentReference

```
fun getDocumentReference(field: String): DocumentReference?
```

Returns the value of the field as a DocumentReference.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `DocumentReference?` | The value of the field |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a DocumentReference. |

### getDouble

```
fun getDouble(field: String): Double?
```

Returns the value of the field as a double.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `Double?` | The value of the field |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a number. |

### getGeoPoint

```
fun getGeoPoint(field: String): GeoPoint?
```

Returns the value of the field as a GeoPoint.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `GeoPoint?` | The value of the field |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a GeoPoint. |

### getId

```
fun getId(): String
```

| Returns |
|---|---|
| `String` | The id of the document. |

### getInt32Value

```
fun getInt32Value(field: String): Int32Value?
```

Returns the value of the field as a 32-bit integer.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `Int32Value?` | The value of the field. |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a `Int32Value`. |

### getLong

```
fun getLong(field: String): Long?
```

Returns the value of the field as a long.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `Long?` | The value of the field |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a number. |

### getMaxKey

```
fun getMaxKey(field: String): MaxKey?
```

Returns the value of the field as a `MaxKey`.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `MaxKey?` | The value of the field. |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a `MaxKey`. |

### getMinKey

```
fun getMinKey(field: String): MinKey?
```

Returns the value of the field as a `MinKey`.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `MinKey?` | The value of the field. |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a `MinKey`. |

### getReference

```
fun getReference(): DocumentReference
```

Gets the reference to the document.

| Returns |
|---|---|
| `DocumentReference` | The reference to the document. |

### getRegexValue

```
fun getRegexValue(field: String): RegexValue?
```

Returns the value of the field as a `RegexValue`.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `RegexValue?` | The value of the field. |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a `RegexValue`. |

### getString

```
fun getString(field: String): String?
```

Returns the value of the field as a String.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `String?` | The value of the field |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a String. |

### getTimestamp

```
fun getTimestamp(field: String): Timestamp?
```

Returns the value of the field as a `com.google.firebase.Timestamp`.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `Timestamp?` | The value of the field |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if this is not a timestamp field. |

### getTimestamp

```
fun getTimestamp(
    field: String,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): Timestamp?
```

Returns the value of the field as a `com.google.firebase.Timestamp`.

| Parameters |
|---|---|
| `field: String` | The path to the field. |
| `serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior` | Configures the behavior for server timestamps that have not yet been set to their final value. |

| Returns |
|---|---|
| `Timestamp?` | The value of the field |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a timestamp field. |

### getVectorValue

```
fun getVectorValue(field: String): VectorValue?
```

Returns the value of the field as a `VectorValue` or `null` if the field does not exist in the document.

| Parameters |
|---|---|
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `VectorValue?` | The value of the field. |

| Throws |
|---|---|
| `java.lang.RuntimeException: java.lang.RuntimeException` | if the value is not a `VectorValue`. |

### hashCode

```
fun hashCode(): Int
```

### toObject

```
fun <T> toObject(valueType: Class<T!>): T?
```

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

| Parameters |
|---|---|
| `valueType: Class<T!>` | 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. |

### toObject

```
fun <T> toObject(
    valueType: Class<T!>,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): T?
```

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

| Parameters |
|---|---|
| `valueType: Class<T!>` | The Java class to create |
| `serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior` | Configures the behavior for server timestamps that have not yet been set to their final value. |

| Returns |
|---|---|
| `T?` | The contents of the document in an object of type T or `null` if the document doesn't exist. |

### toString

```
fun toString(): String
```

## Public properties

### metadata

```
val metadata: SnapshotMetadata!
```

## Extension functions

### getField

```
inline fun <T : Any?> DocumentSnapshot.getField(field: String): T?
```

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

| Parameters |
|---|---|
| `<T : Any?>` | The type to convert the field value to. |
| `field: String` | The path to the field. |

| Returns |
|---|---|
| `T?` | The value at the given field or null. |

### getField

```
inline fun <T : Any?> DocumentSnapshot.getField(
    field: String,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): T?
```

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

| Parameters |
|---|---|
| `<T : Any?>` | The type to convert the field value to. |
| `field: String` | The path to the field. |
| `serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior` | Configures the behavior for server timestamps that have not yet ```kotlin been set to their final value. @return ``` The value at the given field or null. |

### getField

```
inline fun <T : Any?> DocumentSnapshot.getField(fieldPath: FieldPath): T?
```

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

| Parameters |
|---|---|
| `<T : Any?>` | The type to convert the field value to. |
| `fieldPath: FieldPath` | The path to the field. |

| Returns |
|---|---|
| `T?` | The value at the given field or null. |

### getField

```
inline fun <T : Any?> DocumentSnapshot.getField(
    fieldPath: FieldPath,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): T?
```

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

| Parameters |
|---|---|
| `<T : Any?>` | The type to convert the field value to. |
| `fieldPath: FieldPath` | The path to the field. |
| `serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior` | Configures the behavior for server timestamps that have not yet ```kotlin been set to their final value. @return ``` The value at the given field or null. |

### toObject

```
inline fun <T : Any?> DocumentSnapshot.toObject(): T?
```

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

| Parameters |
|---|---|
| `<T : Any?>` | 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 ```kotlin exist. ``` |

### toObject

```
inline fun <T : Any?> DocumentSnapshot.toObject(
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): T?
```

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

| Parameters |
|---|---|
| `<T : Any?>` | The type of the object to create. |
| `serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior` | Configures the behavior for server timestamps that have not yet ```kotlin been set to their final value. @return ``` The contents of the document in an object of type T or null if the document doesn't ```kotlin exist. ``` |