DocumentReference | Doclava
public class

DocumentReference

extends Object
java.lang.Object
   ↳ com.google.firebase.firestore.DocumentReference

Class Overview

A DocumentReference refers to a document location in a Firestore database and can be used to write, read, or listen to the location. 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.

Subclassing Note: Firestore classes are not meant to be subclassed except for use in test mocks. Subclassing is not supported in production code and new SDK releases may break code that does so.

Summary

Public Methods
ListenerRegistration addSnapshotListener(Activity activity, DocumentListenOptions options, EventListener<DocumentSnapshot> listener)
Starts listening to the document referenced by this DocumentReference with the given options using an Activity-scoped listener.
ListenerRegistration addSnapshotListener(Executor executor, DocumentListenOptions options, EventListener<DocumentSnapshot> listener)
Starts listening to the document referenced by this DocumentReference with the given options.
ListenerRegistration addSnapshotListener(EventListener<DocumentSnapshot> listener)
Starts listening to the document referenced by this DocumentReference.
ListenerRegistration addSnapshotListener(DocumentListenOptions options, EventListener<DocumentSnapshot> listener)
Starts listening to the document referenced by this DocumentReference with the given options.
ListenerRegistration addSnapshotListener(Executor executor, EventListener<DocumentSnapshot> listener)
Starts listening to the document referenced by this DocumentReference.
ListenerRegistration addSnapshotListener(Activity activity, EventListener<DocumentSnapshot> listener)
Starts listening to the document referenced by this DocumentReference using an Activity-scoped listener.
CollectionReference collection(String collectionPath)
Gets a CollectionReference instance that refers to the subcollection at the specified path relative to this document.
Task<Void> delete()
Deletes the document referred to by this DocumentReference.
Task<DocumentSnapshot> get()
Reads the document referenced by this DocumentReference
FirebaseFirestore getFirestore()
Gets the Firestore instance associated with this document reference.
String getId()
CollectionReference getParent()
Gets a CollectionReference to the collection that contains this document.
String getPath()
Gets the path of this document (relative to the root of the database) as a slash-separated string.
Task<Void> set(Object pojo)
Overwrites the document referred to by this DocumentReference.
Task<Void> set(Map<String, Object> data, SetOptions options)
Writes to the document referred to by this DocumentReference.
Task<Void> set(Object pojo, SetOptions options)
Writes to the document referred to by this DocumentReference.
Task<Void> set(Map<String, Object> data)
Overwrites the document referred to by this DocumentReference.
Task<Void> update(Map<String, Object> data)
Updates fields in the document referred to by this DocumentReference.
Task<Void> update(String field, Object value, Object... moreFieldsAndValues)
Updates fields in the document referred to by this DocumentReference.
Task<Void> update(FieldPath fieldPath, Object value, Object... moreFieldsAndValues)
Updates fields in the document referred to by this DocumentReference.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public ListenerRegistration addSnapshotListener (Activity activity, DocumentListenOptions options, EventListener<DocumentSnapshot> listener)

Starts listening to the document referenced by this DocumentReference with the given options using an Activity-scoped listener.

The listener will be automatically removed during onStop().

Parameters
activity Activity:The activity to scope the listener to.

options DocumentListenOptions:The options to use for this listen.

listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotListener (Executor executor, DocumentListenOptions options, EventListener<DocumentSnapshot> listener)

Starts listening to the document referenced by this DocumentReference with the given options.

Parameters
executor Executor:The executor to use to call the listener.

options DocumentListenOptions:The options to use for this listen.

listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotListener (EventListener<DocumentSnapshot> listener)

Starts listening to the document referenced by this DocumentReference.

Parameters
listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotListener (DocumentListenOptions options, EventListener<DocumentSnapshot> listener)

Starts listening to the document referenced by this DocumentReference with the given options.

Parameters
options DocumentListenOptions:The options to use for this listen.

listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotListener (Executor executor, EventListener<DocumentSnapshot> listener)

Starts listening to the document referenced by this DocumentReference.

Parameters
executor Executor:The executor to use to call the listener.

listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotListener (Activity activity, EventListener<DocumentSnapshot> listener)

Starts listening to the document referenced by this DocumentReference using an Activity-scoped listener.

The listener will be automatically removed during onStop().

Parameters
activity Activity:The activity to scope the listener to.

listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public CollectionReference collection (String collectionPath)

Gets a CollectionReference instance that refers to the subcollection at the specified path relative to this document.

Parameters
collectionPath String:A slash-separated relative path to a subcollection.

Returns
CollectionReference The CollectionReference instance.

public Task<Void> delete ()

Deletes the document referred to by this DocumentReference.

Returns
Task<Void> A Task that will be resolved when the delete completes.

public Task<DocumentSnapshot> get ()

Reads the document referenced by this DocumentReference

Returns
Task<DocumentSnapshot> A Task that will be resolved with the contents of the Document at this DocumentReference.

public FirebaseFirestore getFirestore ()

Gets the Firestore instance associated with this document reference.

Returns
FirebaseFirestore

public String getId ()

Returns
String

public CollectionReference getParent ()

Gets a CollectionReference to the collection that contains this document.

Returns
CollectionReference The CollectionReference that contains this document.

public String getPath ()

Gets the path of this document (relative to the root of the database) as a slash-separated string.

Returns
String The path of this document.

public Task<Void> set (Object pojo)

Overwrites the document referred to by this DocumentReference. If the document does not yet exist, it will be created. If a document already exists, it will be overwritten.

Parameters
pojo Object:The POJO that will be used to populate the document contents

Returns
Task<Void> A Task that will be resolved when the write finishes.

public Task<Void> set (Map<String, Object> data, SetOptions options)

Writes to the document referred to by this DocumentReference. If the document does not yet exist, it will be created. If you pass SetOptions, the provided data can be merged into an existing document.

Parameters
data Map:A map of the fields and values for the document.

options SetOptions:An object to configure the set behavior.

Returns
Task<Void> A Task that will be resolved when the write finishes.

public Task<Void> set (Object pojo, SetOptions options)

Writes to the document referred to by this DocumentReference. If the document does not yet exist, it will be created. If you pass SetOptions, the provided data can be merged into an existing document.

Parameters
pojo Object:The POJO that will be used to populate the document contents

options SetOptions:An object to configure the set behavior.

Returns
Task<Void> A Task that will be resolved when the write finishes.

public Task<Void> set (Map<String, Object> data)

Overwrites the document referred to by this DocumentReference. If the document does not yet exist, it will be created. If a document already exists, it will be overwritten.

Parameters
data Map:A map of the fields and values for the document.

Returns
Task<Void> A Task that will be resolved when the write finishes.

public Task<Void> update (Map<String, Object> data)

Updates fields in the document referred to by this DocumentReference. If no document exists yet, the update will fail.

Parameters
data Map:A map of field / value pairs to update. Fields can contain dots to reference nested fields within the document.

Returns
Task<Void> A Task that will be resolved when the write finishes.

public Task<Void> update (String field, Object value, Object... moreFieldsAndValues)

Updates fields in the document referred to by this DocumentReference. If no document exists yet, the update will fail.

Parameters
field String:The first field to update. Fields can contain dots to reference a nested field within the document.

value Object:The first value

moreFieldsAndValues Object:Additional field/value pairs.

Returns
Task<Void> A Task that will be resolved when the write finishes.

public Task<Void> update (FieldPath fieldPath, Object value, Object... moreFieldsAndValues)

Updates fields in the document referred to by this DocumentReference. If no document exists yet, the update will fail.

Parameters
fieldPath FieldPath:The first field to update.

value Object:The first value

moreFieldsAndValues Object:Additional field/value pairs.

Returns
Task<Void> A Task that will be resolved when the write finishes.