Firestore API - Class DocumentSnapshot (3.1.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

GoogleCloudFirestore

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
TypeDescription
Timestamp

Database

public FirestoreDb Database { get; }

The database that owns the document.

Property Value
TypeDescription
FirestoreDb

Exists

public bool Exists { get; }

Whether or not the document exists.

Property Value
TypeDescription
bool

Id

public string Id { get; }

The ID of the document.

Property Value
TypeDescription
string

ReadTime

public Timestamp ReadTime { get; }

The time at which this snapshot was read.

Property Value
TypeDescription
Timestamp

Reference

public DocumentReference Reference { get; }

The full reference to the document.

Property Value
TypeDescription
DocumentReference

UpdateTime

public Timestamp? UpdateTime { get; }

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

Property Value
TypeDescription
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
NameDescription
pathFieldPath

The field path to check. Must not be null.

Returns
TypeDescription
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
NameDescription
pathstring

The dot-separated field path to check. Must not be null or empty.

Returns
TypeDescription
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
TypeDescription
T

The deserialized data, or null if this object represents a missing document.

Type Parameter
NameDescription
T

The type to deserialize the document data as.

GetHashCode()

public override int GetHashCode()
Returns
TypeDescription
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
NameDescription
pathFieldPath

The field path to fetch. Must not be null.

Returns
TypeDescription
T

The deserialized value.

Type Parameter
NameDescription
T
Exceptions
TypeDescription
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
NameDescription
pathstring

The dot-separated field path to fetch. Must not be null or empty

Returns
TypeDescription
T

The deserialized value.

Type Parameter
NameDescription
T
Exceptions
TypeDescription
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
TypeDescription
Dictionarystringobject

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

Exceptions
TypeDescription
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
NameDescription
pathFieldPath

The field path to fetch. Must not be null.

valueT

When this method returns, contains the deserialized value if the field was found, or the default value of T otherwise.

Returns
TypeDescription
bool

true if the field was found; false otherwise.

Type Parameter
NameDescription
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
NameDescription
pathstring

The dot-separated field path to fetch. Must not be null or empty

valueT

When this method returns, contains the deserialized value if the field was found, or the default value of T otherwise.

Returns
TypeDescription
bool

true if the field was found; false otherwise.

Type Parameter
NameDescription
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.