Package com.google.cloud.firestore
Class CollectionReference
java.lang.Object
com.google.cloud.firestore.StreamableQuery<QuerySnapshot>
com.google.cloud.firestore.Query
com.google.cloud.firestore.CollectionReference
A CollectionReference can be used for adding documents, getting document references, and querying
for documents (using the methods inherited from Query).
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.cloud.firestore.Query
Query.Direction -
Method Summary
Modifier and TypeMethodDescriptioncom.google.api.core.ApiFuture<DocumentReference>Adds a new document to this collection with the specified POJO as contents, assigning it a document ID automatically.com.google.api.core.ApiFuture<DocumentReference>Adds a new document to this collection with the specified data, assigning it a document ID automatically.document()Returns a DocumentReference pointing to a new document with an auto-generated ID within this collection.Gets a DocumentReference instance that refers to the document that is a child of this Collection.getId()The id of a collection refers to the last component of path pointing to a collection, for example "collection-id" in "projects/project-id/databases/database-id/documents/collection-id".Returns a DocumentReference to the containing Document if this is a subcollection, else null.getPath()A string representing the path of the referenced collection (relative to the root of the database).Retrieves the list of documents in this collection.Methods inherited from class com.google.cloud.firestore.Query
addSnapshotListener, addSnapshotListener, aggregate, count, endAt, endAt, endBefore, endBefore, equals, explain, explainStream, findNearest, findNearest, findNearest, findNearest, fromProto, get, hashCode, limit, limitToLast, offset, orderBy, orderBy, orderBy, orderBy, select, select, startAfter, startAfter, startAt, startAt, stream, toProto, toRunQueryRequestBuilder, where, whereArrayContains, whereArrayContains, whereArrayContainsAny, whereArrayContainsAny, whereEqualTo, whereEqualTo, whereGreaterThan, whereGreaterThan, whereGreaterThanOrEqualTo, whereGreaterThanOrEqualTo, whereIn, whereIn, whereLessThan, whereLessThan, whereLessThanOrEqualTo, whereLessThanOrEqualTo, whereNotEqualTo, whereNotEqualTo, whereNotIn, whereNotInMethods inherited from class com.google.cloud.firestore.StreamableQuery
getFirestore, toString
-
Method Details
-
getId
The id of a collection refers to the last component of path pointing to a collection, for example "collection-id" in "projects/project-id/databases/database-id/documents/collection-id".- Returns:
- The ID of the collection.
-
getParent
Returns a DocumentReference to the containing Document if this is a subcollection, else null.- Returns:
- A DocumentReference pointing to the parent document.
-
getPath
A string representing the path of the referenced collection (relative to the root of the database).- Returns:
- The slash-separated path relative to the root of the database.
-
document
Returns a DocumentReference pointing to a new document with an auto-generated ID within this collection.- Returns:
- A DocumentReference pointing to a new document with an auto-generated ID.
-
document
Gets a DocumentReference instance that refers to the document that is a child of this Collection.- Parameters:
childPath- A relative and slash-separated path to a document.- Returns:
- The DocumentReference instance.
-
listDocuments
Retrieves the list of documents in this collection.The document references returned may include references to "missing documents", specifically document locations that have no document present but which contain subcollections with documents. Attempting to read such a document reference (for example via `get()` or `onSnapshot()`) will return a `DocumentSnapshot` whose `exists()` method returns false.
- Returns:
- The list of documents in this collection.
-
add
@Nonnull public com.google.api.core.ApiFuture<DocumentReference> add(@Nonnull Map<String, Object> fields) Adds a new document to this collection with the specified data, assigning it a document ID automatically.- Parameters:
fields- A Map containing the data for the new document.- Returns:
- An ApiFuture that will be resolved with the DocumentReference of the newly created document.
- See Also:
-
add
Adds a new document to this collection with the specified POJO as contents, assigning it a document ID automatically.- Parameters:
pojo- The POJO that will be used to populate the contents of the document- Returns:
- An ApiFuture that will be resolved with the DocumentReference of the newly created document.
- See Also:
-