Class DocumentSnapshot
An immutable snapshot of the data for a document.
Implements
Namespace: Google.Cloud.Firestore
Assembly: Google.Cloud.Firestore.dll
Syntax
public sealed class DocumentSnapshot : IEquatable<DocumentSnapshot>
Properties
CreateTime
The creation time of the document if it exists, or null otherwise.
Declaration
public Timestamp? CreateTime { get; }
Property Value
Type | Description |
---|---|
Timestamp? |
Database
The database that owns the document.
Declaration
public FirestoreDb Database { get; }
Property Value
Type | Description |
---|---|
FirestoreDb |
Exists
Whether or not the document exists.
Declaration
public bool Exists { get; }
Property Value
Type | Description |
---|---|
bool |
Id
The ID of the document.
Declaration
public string Id { get; }
Property Value
Type | Description |
---|---|
string |
ReadTime
The time at which this snapshot was read.
Declaration
public Timestamp ReadTime { get; }
Property Value
Type | Description |
---|---|
Timestamp |
Reference
The full reference to the document.
Declaration
public DocumentReference Reference { get; }
Property Value
Type | Description |
---|---|
DocumentReference |
UpdateTime
The update time of the document if it exists, or null otherwise.
Declaration
public Timestamp? UpdateTime { get; }
Property Value
Type | Description |
---|---|
Timestamp? |
Methods
ContainsField(FieldPath)
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.
Declaration
public bool ContainsField(FieldPath path)
Parameters
Type | Name | Description |
---|---|---|
FieldPath | path | The field path to check. Must not be null. |
Returns
Type | Description |
---|---|
bool | true if the specified path represents a field in the document; false otherwise |
ContainsField(string)
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.
Declaration
public bool ContainsField(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | The dot-separated field path to check. Must not be null or empty. |
Returns
Type | Description |
---|---|
bool | true if the specified path represents a field in the document; false otherwise |
ConvertTo<T>()
Deserializes the document data as the specified type.
Declaration
public T ConvertTo<T>()
Returns
Type | Description |
---|---|
T | The deserialized data, or null if this object represents a missing document. |
Type Parameters
Name | Description |
---|---|
T | The type to deserialize the document data as. |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int |
Overrides
GetValue<T>(FieldPath)
Fetches a field value from the document, throwing an exception if the field does not exist.
Declaration
public T GetValue<T>(FieldPath path)
Parameters
Type | Name | Description |
---|---|---|
FieldPath | path | The field path to fetch. Must not be null. |
Returns
Type | Description |
---|---|
T | The deserialized value. |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The field does not exist in the document data. |
GetValue<T>(string)
Fetches a field value from the document, throwing an exception if the field does not exist.
Declaration
public T GetValue<T>(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | The dot-separated field path to fetch. Must not be null or empty |
Returns
Type | Description |
---|---|
T | The deserialized value. |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The field does not exist in the document data. |
ToDictionary()
Returns the document data as a Dictionary<TKey, TValue>.
Declaration
public Dictionary<string, object> ToDictionary()
Returns
Type | Description |
---|---|
Dictionary<string, object> | A Dictionary<TKey, TValue> containing the document data, or null if this object represents a missing document. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | This snapshot represents a missing document, i.e. Exists is false. |
TryGetValue<T>(FieldPath, out T)
Attempts to fetch the given field path from the document, returning whether or not it was found, and deserializing it if it was found.
Declaration
public bool TryGetValue<T>(FieldPath path, out T value)
Parameters
Type | Name | Description |
---|---|---|
FieldPath | path | The field path to fetch. Must not be null. |
T | value | When this method returns, contains the deserialized value if the field was found, or the default value
of |
Returns
Type | Description |
---|---|
bool | true if the field was found; false otherwise. |
Type Parameters
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)
Attempts to fetch the given field path from the document, returning whether or not it was found, and deserializing it if it was found.
Declaration
public bool TryGetValue<T>(string path, out T value)
Parameters
Type | Name | Description |
---|---|---|
string | path | The dot-separated field path to fetch. Must not be null or empty |
T | value | When this method returns, contains the deserialized value if the field was found, or the default value
of |
Returns
Type | Description |
---|---|
bool | true if the field was found; false otherwise. |
Type Parameters
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.