Skip to content

collection

numerous.collections.collection

Get or create a collection by name.

collection(collection_key, _client=None)

Get or create a root collection by key.

Use this function as an entry point to interact with collections. If the collection does not exist, it is created.

Parameters:

Name Type Description Default
collection_key str

Key of the collection. A key is a string that uniquely identifies a collection.

required

Returns:

Type Description
CollectionReference

The collection identified by the given key.

Source code in numerous/collections/collection.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def collection(
    collection_key: str, _client: Client | None = None
) -> CollectionReference:
    """
    Get or create a root collection by key.

    Use this function as an entry point to interact with collections.
    If the collection does not exist, it is created.

    Args:
        collection_key: Key of the collection. A key is a string that uniquely
            identifies a collection.

    Returns:
        The collection identified by the given key.

    """
    if _client is None:
        _client = get_client()

    collection_ref = _client.collection_reference(collection_key)

    return CollectionReference(collection_ref.id, collection_ref.key, _client)