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.
An ApiFuture that will be resolved with the contents of the Document at this DocumentReference, or a failure if the document does not exist.
get(FieldMask fieldMask)
public ApiFuture<DocumentSnapshot> get(FieldMask fieldMask)
Reads the document referenced by this DocumentReference. If the document doesn't exist, the get(FieldMask fieldMask) will return an empty DocumentSnapshot.
Parameter
Name
Description
fieldMask
FieldMaskA FieldMask object to retrieve the field value
The id of a document refers to the last component of path pointing to a document, for example "document-id" in "projects/project-id/databases/database-id/document-id".
An Iterable that can be used to fetch all subcollections.
set(Object pojo)
public ApiFuture<WriteResult> set(Object pojo)
Overwrites the document referred to by this DocumentReference. If no document exists yet, it will be created. If a document already exists, it will be overwritten.
Parameter
Name
Description
pojo
ObjectThe POJO that will be used to populate the document contents.
An ApiFuture that will be resolved when the write finishes.
set(Object pojo, SetOptions options)
public ApiFuture<WriteResult> 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
Name
Description
pojo
ObjectThe POJO that will be used to populate the document contents.
options
SetOptionsAn object to configure the set behavior.
An ApiFuture that will be resolved when the write finishes.
set(Map<String,Object> fields)
public ApiFuture<WriteResult> set(Map<String,Object> fields)
Overwrites the document referred to by this DocumentReference. If no document exists yet, it will be created. If a document already exists, it will be overwritten.
Parameter
Name
Description
fields
Map<String,Object>A map of the fields and values for the document.
public ApiFuture<WriteResult> set(Map<String,Object> fields, 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
Name
Description
fields
Map<String,Object>A map of the fields and values for the document.
options
SetOptionsAn object to configure the set behavior.