@InternalExtensionOnly public class DocumentReference extends Object
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.
Modifier and Type | Method and Description |
---|---|
ListenerRegistration |
addSnapshotListener(EventListener<DocumentSnapshot> listener)
Starts listening to the document referenced by this DocumentReference.
|
ListenerRegistration |
addSnapshotListener(Executor executor,
EventListener<DocumentSnapshot> listener)
Starts listening to the document referenced by this DocumentReference.
|
CollectionReference |
collection(String collectionPath)
Gets a CollectionReference instance that refers to the collection that is a child of this
document.
|
com.google.api.core.ApiFuture<WriteResult> |
create(Map<String,Object> fields)
Creates a new Document at the DocumentReference's Location.
|
com.google.api.core.ApiFuture<WriteResult> |
create(Object pojo)
Creates a new Document at the DocumentReference location.
|
com.google.api.core.ApiFuture<WriteResult> |
delete()
Deletes the document referred to by this DocumentReference.
|
com.google.api.core.ApiFuture<WriteResult> |
delete(Precondition options)
Deletes the document referred to by this DocumentReference.
|
boolean |
equals(Object obj)
Returns true if this DocumentReference is equal to the provided object.
|
com.google.api.core.ApiFuture<DocumentSnapshot> |
get()
Reads the document referenced by this DocumentReference.
|
com.google.api.core.ApiFuture<DocumentSnapshot> |
get(FieldMask fieldMask)
Reads the document referenced by this DocumentReference.
|
Firestore |
getFirestore() |
String |
getId()
The id of a document refers to the last component of path pointing to a document, e.g.
|
CollectionReference |
getParent()
A reference to the Collection to which this DocumentReference belongs to.
|
String |
getPath()
A string representing the path of the referenced document (relative to the root of the
database).
|
int |
hashCode() |
Iterable<CollectionReference> |
listCollections()
Fetches the subcollections that are direct children of this document.
|
com.google.api.core.ApiFuture<WriteResult> |
set(Map<String,Object> fields)
Overwrites the document referred to by this DocumentReference.
|
com.google.api.core.ApiFuture<WriteResult> |
set(Map<String,Object> fields,
SetOptions options)
Writes to the document referred to by this DocumentReference.
|
com.google.api.core.ApiFuture<WriteResult> |
set(Object pojo)
Overwrites the document referred to by this DocumentReference.
|
com.google.api.core.ApiFuture<WriteResult> |
set(Object pojo,
SetOptions options)
Writes to the document referred to by this DocumentReference.
|
String |
toString() |
com.google.api.core.ApiFuture<WriteResult> |
update(FieldPath fieldPath,
Object value,
Object... moreFieldsAndValues)
Updates the fields in the document referred to by this DocumentReference.
|
com.google.api.core.ApiFuture<WriteResult> |
update(Map<String,Object> fields)
Updates fields in the document referred to by this DocumentReference.
|
com.google.api.core.ApiFuture<WriteResult> |
update(Map<String,Object> fields,
Precondition options)
Updates fields in the document referred to by this DocumentReference.
|
com.google.api.core.ApiFuture<WriteResult> |
update(Precondition options,
FieldPath fieldPath,
Object value,
Object... moreFieldsAndValues)
Updates the fields in the document referred to by this DocumentReference.
|
com.google.api.core.ApiFuture<WriteResult> |
update(Precondition options,
String field,
Object value,
Object... moreFieldsAndValues)
Updates the fields in the document referred to by this DocumentReference.
|
com.google.api.core.ApiFuture<WriteResult> |
update(String field,
Object value,
Object... moreFieldsAndValues)
Updates the fields in the document referred to by this DocumentReference.
|
@Nonnull public String getId()
@Nonnull public String getPath()
@Nonnull public CollectionReference getParent()
@Nonnull public CollectionReference collection(@Nonnull String collectionPath)
collectionPath
- A relative and slash-separated path to a collection.@Nonnull public com.google.api.core.ApiFuture<WriteResult> create(@Nonnull Map<String,Object> fields)
fields
- A map of the fields and values for the document.@Nonnull public com.google.api.core.ApiFuture<WriteResult> create(@Nonnull Object pojo)
pojo
- The POJO that will be used to populate the document contents.@Nonnull public com.google.api.core.ApiFuture<WriteResult> set(@Nonnull Map<String,Object> fields)
fields
- A map of the fields and values for the document.@Nonnull public com.google.api.core.ApiFuture<WriteResult> set(@Nonnull Map<String,Object> fields, @Nonnull SetOptions options)
SetOptions
, the provided data can be merged into
an existing document.fields
- A map of the fields and values for the document.options
- An object to configure the set behavior.@Nonnull public com.google.api.core.ApiFuture<WriteResult> set(@Nonnull Object pojo)
pojo
- The POJO that will be used to populate the document contents.@Nonnull public com.google.api.core.ApiFuture<WriteResult> set(@Nonnull Object pojo, @Nonnull SetOptions options)
SetOptions
, the provided data can be merged into
an existing document.pojo
- The POJO that will be used to populate the document contents.options
- An object to configure the set behavior.@Nonnull public com.google.api.core.ApiFuture<WriteResult> update(@Nonnull Map<String,Object> fields)
fields
- A Map containing the fields and values with which to update the document.@Nonnull public com.google.api.core.ApiFuture<WriteResult> update(@Nonnull Map<String,Object> fields, Precondition options)
fields
- A map containing the fields and values with which to update the document.options
- Preconditions to enforce on this update.@Nonnull public com.google.api.core.ApiFuture<WriteResult> update(@Nonnull String field, @Nullable Object value, Object... moreFieldsAndValues)
field
- The first field to setvalue
- The first value to setmoreFieldsAndValues
- String and Object pairs with more fields to be set.@Nonnull public com.google.api.core.ApiFuture<WriteResult> update(@Nonnull FieldPath fieldPath, @Nullable Object value, Object... moreFieldsAndValues)
fieldPath
- The first field to setvalue
- The first value to setmoreFieldsAndValues
- String and Object pairs with more fields to be set.@Nonnull public com.google.api.core.ApiFuture<WriteResult> update(@Nonnull Precondition options, @Nonnull String field, @Nullable Object value, Object... moreFieldsAndValues)
options
- Preconditions to enforce on this update.field
- The first field to setvalue
- The first value to setmoreFieldsAndValues
- String and Object pairs with more fields to be set.@Nonnull public com.google.api.core.ApiFuture<WriteResult> update(@Nonnull Precondition options, @Nonnull FieldPath fieldPath, @Nullable Object value, Object... moreFieldsAndValues)
options
- Preconditions to enforce on this update.fieldPath
- The first field to setvalue
- The first value to setmoreFieldsAndValues
- String and Object pairs with more fields to be set.@Nonnull public com.google.api.core.ApiFuture<WriteResult> delete(@Nonnull Precondition options)
options
- Preconditions to enforce for this delete.@Nonnull public com.google.api.core.ApiFuture<WriteResult> delete()
@Nonnull public com.google.api.core.ApiFuture<DocumentSnapshot> get()
@Nonnull public com.google.api.core.ApiFuture<DocumentSnapshot> get(FieldMask fieldMask)
fieldMask
- A FieldMask object to retrieve the field value@Nonnull public Iterable<CollectionReference> listCollections()
FirestoreException
- if the Iterable could not be initialized.@Nonnull public ListenerRegistration addSnapshotListener(@Nonnull Executor executor, @Nonnull EventListener<DocumentSnapshot> listener)
executor
- The executor to use to call the listener.listener
- The event listener that will be called with the snapshots.@Nonnull public ListenerRegistration addSnapshotListener(@Nonnull EventListener<DocumentSnapshot> listener)
listener
- The event listener that will be called with the snapshots.public boolean equals(Object obj)
Copyright © 2023 Google LLC. All rights reserved.