Firestore API - Class DocumentSnapshot (3.9.0)

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

Namespace

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
Timestamp

Database

public FirestoreDb Database { get; }

The database that owns the document.

Property Value
Type Description
FirestoreDb

Exists

public bool Exists { get; }

Whether or not the document exists.

Property Value
Type Description
bool

Id

public string Id { get; }

The ID of the document.

Property Value
Type Description
string

ReadTime

public Timestamp ReadTime { get; }

The time at which this snapshot was read.

Property Value
Type Description
Timestamp

Reference

public DocumentReference Reference { get; }

The full reference to the document.

Property Value
Type Description
DocumentReference

UpdateTime

public Timestamp? UpdateTime { get; }

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

Property Value
Type Description
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 FieldPath

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)

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 string

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>()

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
int
Overrides

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

Returns
Type Description
Dictionarystringobject

A Dictionary<TKey, TValue> containing the document data, or null if this object represents a missing document.

Exceptions
Type Description
InvalidOperationException

This snapshot represents a missing document, i.e. 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 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
bool

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

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.