Skip to content

Support collection group queries #35

@gresnick

Description

@gresnick

Currently it is only possible to get a subcollection from a single document:

class UserStats(AsyncSubModel):
    id: Optional[str]
    purchases: int = 0

    class Collection(AsyncSubCollection):
        # Can use any properties of the "parent" model
        __collection_tpl__ = "users/{id}/stats"


class User(AsyncModel):
    __collection__ = "users"
    name: str

async def get_user_stats(user_id):
    user = await User.get_by_id(user_id)
    stats_model: Type[UserStats] = UserStats.model_for(user)

Ideally, the ability to query all user stats (as supported by firestore's group query):

UserStats.collection.find({"reported_at": {"<=": "datetime.datetime.utcnow()"}})

Side note: It would be awesome to not have to retrieve the user before querying its subcollection

UserStats.model_for(user)

or

UserStats.parent(user_id)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions