CollectionReference

public class CollectionReference extends Query

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.

Public Method Summary

Task<DocumentReference>
add(Map<StringObject> data)
Adds a new document to this collection with the specified data, assigning it a document ID automatically.
Task<DocumentReference>
add(Object pojo)
Adds a new document to this collection with the specified POJO as contents, assigning it a document ID automatically.
DocumentReference
document()
Returns a DocumentReference pointing to a new document with an auto-generated ID within this collection.
DocumentReference
document(String documentPath)
Gets a DocumentReference instance that refers to the document at the specified path within this collection.
String
DocumentReference
getParent()
Gets a DocumentReference to the document that contains this collection.
String
getPath()
Gets the path of this collection (relative to the root of the database) as a slash-separated string.

Inherited Method Summary

Public Methods

public Task<DocumentReference> add (Map<StringObject> data)

Adds a new document to this collection with the specified data, assigning it a document ID automatically.

Parameters
data A Map containing the data for the new document.
Returns
  • A Task that will be resolved with the DocumentReference of the newly created document.

public Task<DocumentReference> add (Object pojo)

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
  • A Task that will be resolved with the DocumentReference of the newly created document.

public DocumentReference 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.

public DocumentReference document (String documentPath)

Gets a DocumentReference instance that refers to the document at the specified path within this collection.

Parameters
documentPath A slash-separated relative path to a document.
Returns
  • The DocumentReference instance.

public String getId ()

Returns
  • The ID of the collection.

public DocumentReference getParent ()

Gets a DocumentReference to the document that contains this collection. Only subcollections are contained in a document. For root collections, returns null.

Returns
  • The DocumentReference that contains this collection or null if this is a root collection.

public String getPath ()

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

Returns
  • The path of this collection.

发送以下问题的反馈:

此网页
需要帮助?请访问我们的支持页面