Firebase.Firestore.DocumentReference

ADocumentReference refers to a document location in a CloudFirestore database and can be used to write, read, or listen to the location.

Summary

There may or may not exist a document at the referenced location. ADocumentReference can also be used to create aCollectionReference to a subcollection.

Inheritance

Inherits from: IEquatable< DocumentReference >

Properties

Firestore
The database which contains the document.

Public attributes

Id => _proxy.id()
string
The final part of the complete document path; this is the identity of the document relative to its parent collection.
Parent => new CollectionReference(_proxy.Parent(), Firestore)
The parent collection.
Path => _proxy.path()
string
The complete document path, not including project and database ID.

Public functions

Collection(string path)
Creates aCollectionReference for a child collection of this document.
DeleteAsync()
Task
Asynchronously deletes the document referred to by thisDocumentReference.
Equals(object obj)
override bool
Equals(DocumentReference other)
bool
GetHashCode()
override int
GetSnapshotAsync(Source source)
Asynchronously fetches a snapshot of the document.
Listen(Action<DocumentSnapshot > callback)
Starts listening to changes to the document referenced by thisDocumentReference.
Listen(MetadataChanges metadataChanges, Action<DocumentSnapshot > callback)
Starts listening to changes to the document referenced by thisDocumentReference.
SetAsync(object documentData,SetOptions options)
Task
Asynchronously sets data in the document, either replacing it completely or merging fields.
ToString()
override string
UpdateAsync(IDictionary< string, object > updates)
Task
Asynchronously performs a set of updates on the document referred to by thisDocumentReference.
UpdateAsync(string field, object value)
Task
Asynchronously performs a single field update on the document referred to by thisDocumentReference.
UpdateAsync(IDictionary<FieldPath, object > updates)
Task
Asynchronously performs a set of updates on the document referred to by thisDocumentReference.

Properties

Firestore

FirebaseFirestoreFirestore

The database which contains the document.

Public attributes

Id

stringId=>_proxy.id()

The final part of the complete document path; this is the identity of the document relative to its parent collection.

Parent

CollectionReferenceParent=>newCollectionReference(_proxy.Parent(),Firestore)

The parent collection.

Nevernull.

Path

stringPath=>_proxy.path()

The complete document path, not including project and database ID.

Public functions

Collection

CollectionReferenceCollection(stringpath)

Creates aCollectionReference for a child collection of this document.

Details
Parameters
path
The path to the collection, relative to this document. Must not benull, and must contain an odd number of slash-separated path elements.
Returns
ACollectionReference for the specified collection.

DeleteAsync

TaskDeleteAsync()

Asynchronously deletes the document referred to by thisDocumentReference.

Details
Returns
The write result of the server operation. The task will not complete while the client is offline, though local changes will be visible immediately.

Equals

overrideboolEquals(objectobj)

Equals

boolEquals(DocumentReferenceother)

GetHashCode

overrideintGetHashCode()

GetSnapshotAsync

Task<DocumentSnapshot>GetSnapshotAsync(Sourcesource)

Asynchronously fetches a snapshot of the document.

By default,GetSnapshotAsync attempts to provide up-to-date data when possible by waiting for data from the server, but it may return cached data or fail if you are offline and the server cannot be reached. This behavior can be altered via thesource parameter.

Details
Parameters
source
indicates whether the results should be fetched from the cache only (Source.Cache), the server only (Source.Server), or to attempt the server and fall back to the cache (Source.Default).
Returns
A snapshot of the document. The snapshot may represent a missing document.

Listen

ListenerRegistrationListen(Action<DocumentSnapshot>callback)

Starts listening to changes to the document referenced by thisDocumentReference.

Details
Parameters
callback
The callback to invoke each time the query results change. Must not benull. The callback will be invoked on the main thread.
Returns
AListenerRegistration which may be used to stop listening gracefully.

Listen

ListenerRegistrationListen(MetadataChangesmetadataChanges,Action<DocumentSnapshot>callback)

Starts listening to changes to the document referenced by thisDocumentReference.

Details
Parameters
metadataChanges
Indicates whether metadata-only changes (i.e. onlyDocumentSnapshot.Metadata changed) should trigger snapshot events.
callback
The callback to invoke each time the query results change. Must not benull. The callback will be invoked on the main thread.
Returns
AListenerRegistration which may be used to stop listening gracefully.

SetAsync

TaskSetAsync(objectdocumentData,SetOptionsoptions)

Asynchronously sets data in the document, either replacing it completely or merging fields.

Details
Parameters
documentData
The data to store in the document. Must not benull.
options
The options to use when updating the document. May benull, which is equivalent toSetOptions.Overwrite.
Returns
The write result of the server operation. The task will not complete while the client is offline, though local changes will be visible immediately.

ToString

overridestringToString()

UpdateAsync

TaskUpdateAsync(IDictionary<string,object>updates)

Asynchronously performs a set of updates on the document referred to by thisDocumentReference.

Details
Parameters
updates
The updates to perform on the document, keyed by the field path to update. Fields not present in this dictionary are not updated. Must not benull.
Returns
The write result of the server operation. The task will not complete while the client is offline, though local changes will be visible immediately.

UpdateAsync

TaskUpdateAsync(stringfield,objectvalue)

Asynchronously performs a single field update on the document referred to by thisDocumentReference.

Details
Parameters
field
The dot-separated name of the field to update. Must not benull.
value
The new value for the field. May benull.
Returns
The write result of the server operation. The task will not complete while the client is offline, though local changes will be visible immediately.

UpdateAsync

TaskUpdateAsync(IDictionary<FieldPath,object>updates)

Asynchronously performs a set of updates on the document referred to by thisDocumentReference.

Details
Parameters
updates
The updates to perform on the document, keyed by the field path to update. Fields not present in this dictionary are not updated. Must not benull.
Returns
The write result of the server operation. The task will not complete while the client is offline, though local changes will be visible immediately.

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 2022-07-27 UTC.