Firebase.Firestore.DocumentSnapshot

An immutable snapshot of the data for a document.

Summary

A DocumentSnapshot contains data read from a document in your Cloud Firestore database. The data can be extracted with the DocumentSnapshot.ToDictionary(ServerTimestampBehavior) or M:DocumentSnapshot.GetValue`1{T}(string, ServerTimestampBehavior) methods.

If the DocumentSnapshot points to a non-existing document, ToDictionary will return null. You can always explicitly check for a document's existence by checking DocumentSnapshot.Exists.

Properties

Metadata
The metadata for this DocumentSnapshot.

Public attributes

Exists => _proxy.exists()
bool
Whether or not the document exists.
Id => _proxy.id()
string
The ID of the document.
Reference => new DocumentReference(_proxy.reference(), _firestore)
The full reference to the document.

Public functions

ContainsField(string path)
bool
Determines whether or not the given field path is present in the document.
ContainsField(FieldPath path)
bool
Determines whether or not the given field path is present in the document.
ConvertTo< T >(ServerTimestampBehavior serverTimestampBehavior)
T
Deserializes the document data as the specified type.
Equals(object obj)
override bool
Equals(DocumentSnapshot other)
bool
GetHashCode()
override int
GetValue< T >(string path, ServerTimestampBehavior serverTimestampBehavior)
T
Fetches a field value from the document, throwing an exception if the field does not exist.
GetValue< T >(FieldPath path, ServerTimestampBehavior serverTimestampBehavior)
T
Fetches a field value from the document, throwing an exception if the field does not exist.
ToDictionary(ServerTimestampBehavior serverTimestampBehavior)
Dictionary< string, object >
Returns the document data as a Dictionary{String, Object}.
TryGetValue< T >(string path, out T value, ServerTimestampBehavior serverTimestampBehavior)
bool
Attempts to fetch the given field value from the document, returning whether or not it was found.
TryGetValue< T >(FieldPath path, out T value, ServerTimestampBehavior serverTimestampBehavior)
bool
Attempts to fetch the given field value from the document, returning whether or not it was found.

Properties

Metadata

SnapshotMetadata Metadata

The metadata for this DocumentSnapshot.

Public attributes

Exists

bool Exists => _proxy.exists()

Whether or not the document exists.

Id

string Id => _proxy.id()

The ID of the document.

Reference

DocumentReference Reference => new DocumentReference(_proxy.reference(), _firestore)

The full reference to the document.

Public functions

ContainsField

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.

Details
Parameters
path
The dot-separated field path to check. Must not be null or empty.
Returns
true if the specified path represents a field in the document; false otherwise.

ContainsField

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.

Details
Parameters
path
The field path to check. Must not be null.
Returns
true if the specified path represents a field in the document; false otherwise.

ConvertTo< T >

T ConvertTo< T >(
  ServerTimestampBehavior serverTimestampBehavior
)

Deserializes the document data as the specified type.

Details
Template Parameters
T
The type to deserialize the document data as.
Parameters
serverTimestampBehavior
Configures the behavior for server timestamps that have not yet been set to their final value.
Returns
The deserialized data or default(T) if this is a nonexistent document.

Equals

override bool Equals(
  object obj
)

Equals

bool Equals(
  DocumentSnapshot other
)

GetHashCode

override int GetHashCode()

GetValue< T >

T GetValue< T >(
  string path,
  ServerTimestampBehavior serverTimestampBehavior
)

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

Details
Parameters
path
The dot-separated field path to fetch. Must not be null or empty.
serverTimestampBehavior
Configures the behavior for server timestamps that have not yet been set to their final value.
Exceptions
InvalidOperationException
The field does not exist in the document data.
Returns
The deserialized value.

GetValue< T >

T GetValue< T >(
  FieldPath path,
  ServerTimestampBehavior serverTimestampBehavior
)

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

Details
Parameters
path
The field path to fetch. Must not be null or empty.
serverTimestampBehavior
Configures the behavior for server timestamps that have not yet been set to their final value.
Exceptions
InvalidOperationException
The field does not exist in the document data.
Returns
The deserialized value.

ToDictionary

Dictionary< string, object > ToDictionary(
  ServerTimestampBehavior serverTimestampBehavior
)

Returns the document data as a Dictionary{String, Object}.

Details
Parameters
serverTimestampBehavior
Configures the behavior for server timestamps that have not yet been set to their final value.
Returns
A Dictionary{String, Object} containing the document data or null if this is a nonexistent document.

TryGetValue< T >

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

Attempts to fetch the given field value from the document, returning whether or not it was found.

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.

Details
Parameters
path
The dot-separated field path to fetch. Must not be null or empty.
value
When this method returns, contains the deserialized value if the field was found, or the default value of T otherwise.
serverTimestampBehavior
Configures the behavior for server timestamps that have not yet been set to their final value.
Returns
true if the field was found in the document; false otherwise.

TryGetValue< T >

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

Attempts to fetch the given field value from the document, returning whether or not it was found.

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.

Details
Parameters
path
The field path to fetch. Must not be null or empty.
value
When this method returns, contains the deserialized value if the field was found, or the default value of T otherwise.
serverTimestampBehavior
Configures the behavior for server timestamps that have not yet been set to their final value.
Returns
true if the field was found in the document; false otherwise.