4.6.0 (latest) 4.5.0 4.4.0 4.3.0 4.2.0 4.1.0 4.0.0 3.13.0 3.12.0 3.11.0 3.10.0 3.9.0 3.8.0 3.7.0 3.6.0 3.5.1 3.4.0 3.3.0 3.2.0 3.1.0 3.0.0 2.5.0 2.4.0 2.3.1

    public sealed class DocumentSnapshot : IEquatable<DocumentSnapshot>

Reference documentation and code samples for the Firestore API class DocumentSnapshot.

An immutable snapshot of the data for a document.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> DocumentSnapshot

## Implements

[IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[DocumentSnapshot](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentSnapshot)

## Inherited Members

[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Cloud.Firestore](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore)

## Assembly

Google.Cloud.Firestore.dll

## Properties

### CreateTime

    public Timestamp? CreateTime { get; }

The creation time of the document if it exists, or null otherwise.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Timestamp` |   |

### Database

    public FirestoreDb Database { get; }

The database that owns the document.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FirestoreDb` |   |

### Exists

    public bool Exists { get; }

Whether or not the document exists.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### Id

    public string Id { get; }

The ID of the document.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### ReadTime

    public Timestamp ReadTime { get; }

The time at which this snapshot was read.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Timestamp` |   |

### Reference

    public DocumentReference Reference { get; }

The full reference to the document.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` |   |

### UpdateTime

    public Timestamp? UpdateTime { get; }

The update time of the document if it exists, or null otherwise.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Timestamp` |   |

## Methods

### ContainsField(FieldPath)

    public bool ContainsField(FieldPath path)

Determines whether or not the given field path is present in the document. If this snapshot represents
a missing document, this method will always return false.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FieldPath` The field path to check. Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | true if the specified path represents a field in the document; false otherwise |

### ContainsField(string)

    public bool ContainsField(string path)

Determines whether or not the given field path is present in the document. If this snapshot represents
a missing document, this method will always return false.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://learn.microsoft.com/dotnet/api/system.string` The dot-separated field path to check. Must not be null or empty. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | true if the specified path represents a field in the document; false otherwise |

### ConvertTo\<T\>()

    public T ConvertTo<T>()

Deserializes the document data as the specified type.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` | The deserialized data, or null if this object represents a missing document. |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` | The type to deserialize the document data as. |

### GetHashCode()

    public override int GetHashCode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int32` |   |

**Overrides** [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode)

### GetValue\<T\>(FieldPath)

    public T GetValue<T>(FieldPath path)

Fetches a field value from the document, throwing an exception if the field does not exist.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FieldPath` The field path to fetch. Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` | The deserialized value. |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.invalidoperationexception` | The field does not exist in the document data. |

### GetValue\<T\>(string)

    public T GetValue<T>(string path)

Fetches a field value from the document, throwing an exception if the field does not exist.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://learn.microsoft.com/dotnet/api/system.string` The dot-separated field path to fetch. Must not be null or empty |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` | The deserialized value. |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.invalidoperationexception` | The field does not exist in the document data. |

### ToDictionary()

    public Dictionary<string, object> ToDictionary()

Returns the document data as a [Dictionary\<TKey, TValue\>](https://learn.microsoft.com/dotnet/api/system.collections.generic.dictionary-2).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.dictionary-2https://learn.microsoft.com/dotnet/api/system.stringhttps://learn.microsoft.com/dotnet/api/system.object` | A [Dictionary\<TKey, TValue\>](https://learn.microsoft.com/dotnet/api/system.collections.generic.dictionary-2) containing the document data, or null if this object represents a missing document. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.invalidoperationexception` | This snapshot represents a missing document, i.e. [Exists](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentSnapshot#Google_Cloud_Firestore_DocumentSnapshot_Exists) is false. |

### TryGetValue\<T\>(FieldPath, out T)

    public bool TryGetValue<T>(FieldPath path, out T value)

Attempts to fetch the given field path from the document, returning whether or not it was found, and deserializing
it if it was found.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FieldPath` The field path to fetch. Must not be null. |
| `value` | `T` When this method returns, contains the deserialized value if the field was found, or the default value of `T` otherwise. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | true if the field was found; false otherwise. |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` | The type to deserialize the value to, if it is found. |

**Remarks** This method does not throw an exception if the field is not found, but does throw an exception if the field was found
but cannot be deserialized.

### TryGetValue\<T\>(string, out T)

    public bool TryGetValue<T>(string path, out T value)

Attempts to fetch the given field path from the document, returning whether or not it was found, and deserializing
it if it was found.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://learn.microsoft.com/dotnet/api/system.string` The dot-separated field path to fetch. Must not be null or empty |
| `value` | `T` When this method returns, contains the deserialized value if the field was found, or the default value of `T` otherwise. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | true if the field was found; false otherwise. |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` | The type to deserialize the value to, if it is found. |

**Remarks** This method does not throw an exception if the field is not found, but does throw an exception if the field was found
but cannot be deserialized.