diff --git a/packages/google-cloud-firestore/google/cloud/firestore_v1/collection.py b/packages/google-cloud-firestore/google/cloud/firestore_v1/collection.py index 19b86ae6559a..757023a8ee41 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_v1/collection.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_v1/collection.py @@ -16,7 +16,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Callable, Generator, Optional, Tuple, Union +from typing import TYPE_CHECKING, Any, Callable, Generator, Optional, Tuple, Union, cast from google.api_core import gapic_v1 from google.api_core import retry as retries @@ -33,6 +33,7 @@ if TYPE_CHECKING: # pragma: NO COVER import datetime + from google.cloud.firestore_v1.document import DocumentReference from google.cloud.firestore_v1.base_document import DocumentSnapshot from google.cloud.firestore_v1.query_profile import ExplainOptions from google.cloud.firestore_v1.stream_generator import StreamGenerator @@ -134,6 +135,23 @@ def add( write_result = document_ref.create(document_data, **kwargs) return write_result.update_time, document_ref + + def document(self, document_id: Union[str, None] = None) -> "DocumentReference": + """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.DocumentReference: + The child document. + """ + doc = super().document(document_id) + return cast("DocumentReference", doc) + def list_documents( self, page_size: Union[int, None] = None,