Firebase.Firestore.DocumentReference

A DocumentReference refers to a document location in a Cloud Firestore 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. A DocumentReference can also be used to create a CollectionReference 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 a CollectionReference for a child collection of this document.
DeleteAsync()
Task
Asynchronously deletes the document referred to by this DocumentReference.
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 this DocumentReference.
Listen(MetadataChanges metadataChanges, Action< DocumentSnapshot > callback)
Starts listening to changes to the document referenced by this DocumentReference.
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 this DocumentReference.
UpdateAsync(string field, object value)
Task
Asynchronously performs a single field update on the document referred to by this DocumentReference.
UpdateAsync(IDictionary< FieldPath, object > updates)
Task
Asynchronously performs a set of updates on the document referred to by this DocumentReference.

Properties

Firestore

FirebaseFirestore Firestore

The database which contains the document.

Public attributes

Id

string Id => _proxy.id()

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

Parent

CollectionReference Parent => new CollectionReference(_proxy.Parent(), Firestore)

The parent collection.

Never null.

Path

string Path => _proxy.path()

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

Public functions

Collection

CollectionReference Collection(
  string path
)

Creates a CollectionReference for a child collection of this document.

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

DeleteAsync

Task DeleteAsync()

Asynchronously deletes the document referred to by this DocumentReference.

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

override bool Equals(
  object obj
)

Equals

bool Equals(
  DocumentReference other
)

GetHashCode

override int GetHashCode()

GetSnapshotAsync

Task< DocumentSnapshot > GetSnapshotAsync(
  Source source
)

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 the source 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

ListenerRegistration Listen(
  Action< DocumentSnapshot > callback
)

Starts listening to changes to the document referenced by this DocumentReference.

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

Listen

ListenerRegistration Listen(
  MetadataChanges metadataChanges,
  Action< DocumentSnapshot > callback
)

Starts listening to changes to the document referenced by this DocumentReference.

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

SetAsync

Task SetAsync(
  object documentData,
  SetOptions options
)

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 be null.
options
The options to use when updating the document. May be null, which is equivalent to SetOptions.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

override string ToString()

UpdateAsync

Task UpdateAsync(
  IDictionary< string, object > updates
)

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

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 be null.
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

Task UpdateAsync(
  string field,
  object value
)

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

Details
Parameters
field
The dot-separated name of the field to update. Must not be null.
value
The new value for the field. May be null.
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

Task UpdateAsync(
  IDictionary< FieldPath, object > updates
)

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

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 be null.
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.