Firebase.Firestore.DocumentSnapshot

An immutable snapshot of the data for a document.

Summary

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

If theDocumentSnapshot points to a non-existing document,ToDictionary will returnnull. You can always explicitly check for a document's existence by checkingDocumentSnapshot.Exists.

Properties

Metadata
The metadata for thisDocumentSnapshot.

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

SnapshotMetadataMetadata

The metadata for thisDocumentSnapshot.

Public attributes

Exists

boolExists=>_proxy.exists()

Whether or not the document exists.

Id

stringId=>_proxy.id()

The ID of the document.

Reference

DocumentReferenceReference=>newDocumentReference(_proxy.reference(),_firestore)

The full reference to the document.

Public functions

ContainsField

boolContainsField(stringpath)

Determines whether or not the given field path is present in the document.

If this snapshot represents a missing document, this method will always returnfalse.

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

ContainsField

boolContainsField(FieldPathpath)

Determines whether or not the given field path is present in the document.

If this snapshot represents a missing document, this method will always returnfalse.

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

ConvertTo< T >

TConvertTo<T>(ServerTimestampBehaviorserverTimestampBehavior)

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 ordefault(T) if this is a nonexistent document.

Equals

overrideboolEquals(objectobj)

Equals

boolEquals(DocumentSnapshotother)

GetHashCode

overrideintGetHashCode()

GetValue< T >

TGetValue<T>(stringpath,ServerTimestampBehaviorserverTimestampBehavior)

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

TGetValue<T>(FieldPathpath,ServerTimestampBehaviorserverTimestampBehavior)

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

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 ornull if this is a nonexistent document.

TryGetValue< T >

boolTryGetValue<T>(stringpath,outTvalue,ServerTimestampBehaviorserverTimestampBehavior)

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 benull or empty.
value
When this method returns, contains the deserialized value if the field was found, or the default value ofT 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 >

boolTryGetValue<T>(FieldPathpath,outTvalue,ServerTimestampBehaviorserverTimestampBehavior)

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 benull or empty.
value
When this method returns, contains the deserialized value if the field was found, or the default value ofT 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.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2021-09-08 UTC.