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 this DocumentSnapshot. |
Public attributes | |
|---|---|
Exists => _proxy.exists() | boolWhether or not the document exists. |
Id => _proxy.id() | stringThe ID of the document. |
Reference => new DocumentReference(_proxy.reference(), _firestore) | The full reference to the document. |
Public functions | |
|---|---|
ContainsField(string path) | boolDetermines whether or not the given field path is present in the document. |
ContainsField(FieldPath path) | boolDetermines whether or not the given field path is present in the document. |
ConvertTo< T >(ServerTimestampBehavior serverTimestampBehavior) | TDeserializes 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) | TFetches a field value from the document, throwing an exception if the field does not exist. |
GetValue< T >(FieldPath path,ServerTimestampBehavior serverTimestampBehavior) | TFetches 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) | boolAttempts 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) | boolAttempts to fetch the given field value from the document, returning whether or not it was found. |
Properties
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 |
| ||
| 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 |
| ||
| 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 |
| ||
| Parameters |
| ||
| Returns | The deserialized data or default(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 |
| ||||
| Exceptions |
| ||||
| 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 |
| ||||
| Exceptions |
| ||||
| Returns | The deserialized value. |
ToDictionary
Dictionary<string,object>ToDictionary(ServerTimestampBehaviorserverTimestampBehavior)
Returns the document data as a Dictionary{String, Object}.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A Dictionary{String, Object} containing the document data or null 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 |
| ||||||
| 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 |
| ||||||
| 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.