diff --git a/google/cloud/firestore_v1/async_collection.py b/google/cloud/firestore_v1/async_collection.py index e3842f03e..ca4ec8b0f 100644 --- a/google/cloud/firestore_v1/async_collection.py +++ b/google/cloud/firestore_v1/async_collection.py @@ -112,6 +112,23 @@ async def add( write_result = await document_ref.create(document_data, **kwargs) return write_result.update_time, document_ref + def document( + self, document_id: str = None + ) -> async_document.AsyncDocumentReference: + """Create a sub-document underneath the current collection. + + Args: + document_id (Optional[str]): The document identifier + within the current collection. If not provided, will default + to a random 20 character string composed of digits, + uppercase and lowercase and letters. + + Returns: + :class:`~google.cloud.firestore_v1.document.async_document.AsyncDocumentReference`: + The child document. + """ + return super(AsyncCollectionReference, self).document(document_id) + async def list_documents( self, page_size: int = None, diff --git a/tests/unit/v1/test_async_collection.py b/tests/unit/v1/test_async_collection.py index a7b3ba0e4..bf0959e04 100644 --- a/tests/unit/v1/test_async_collection.py +++ b/tests/unit/v1/test_async_collection.py @@ -57,6 +57,12 @@ def test_query_method_matching(self): # ``AsyncCollectionReference``. self.assertLessEqual(query_methods, collection_methods) + def test_document_name_default(self): + client = _make_client() + document = client.collection("test").document() + # name is random, but assert it is not None + self.assertTrue(document.id is not None) + def test_constructor(self): collection_id1 = "rooms" document_id = "roomA"