def aggregate(collection, pipelines, hints=None, _stream=False):
    """Executes one or more aggregations on a collection.

    Multiple aggregations are executed using multiple threads, and their
    results are returned as lists rather than cursors.

    Args:
        collection: a ``pymongo.collection.Collection`` or
            ``motor.motor_asyncio.AsyncIOMotorCollection``
        pipelines: a MongoDB aggregation pipeline or a list of pipelines
        hints (None): a corresponding index hint or list of index hints for
            each pipeline

    Returns:
        -   If a single pipeline is provided, a
            ``pymongo.command_cursor.CommandCursor`` or
            ``motor.motor_asyncio.AsyncIOMotorCommandCursor`` is returned

        -   If multiple pipelines are provided, each cursor is extracted into
            a list and the list of lists is returned
    """
    pipelines = list(pipelines)
    is_list = pipelines and not isinstance(pipelines[0], dict)
    if not is_list:
        pipelines = [pipelines]
        hints = [hints]

    num_pipelines = len(pipelines)
    if hints is None:
        hints = [None] * num_pipelines

    if isinstance(collection, mtr.AsyncIOMotorCollection):
        if num_pipelines == 1 and not is_list:
            kwargs = {"hint": hints[0]} if hints[0] is not None else {}
            return collection.aggregate(
                pipelines[0], allowDiskUse=True, **kwargs
            )

        return _do_async_pooled_aggregate(collection, pipelines, hints)

    if num_pipelines == 1:
        kwargs = {"hint": hints[0]} if hints[0] is not None else {}
        result = collection.aggregate(
            pipelines[0], allowDiskUse=True, **kwargs
        )
        if _stream:
            return result
        return [result] if is_list else result

    return _do_pooled_aggregate(collection, pipelines, hints, _stream=_stream)
Executes one or more aggregations on a collection.

    Multiple aggregations are executed using multiple threads, and their
    results are returned as lists rather than cursors.

    Args:
        collection: a ``pymongo.collection.Collection`` or
            ``motor.motor_asyncio.AsyncIOMotorCollection``
        pipelines: a MongoDB aggregation pipeline or a list of pipelines
        hints (None): a corresponding index hint or list of index hints for
            each pipeline

    Returns:
        -   If a single pipeline is provided, a
            ``pymongo.command_cursor.CommandCursor`` or
            ``motor.motor_asyncio.AsyncIOMotorCommandCursor`` is returned

        -   If multiple pipelines are provided, each cursor is extracted into
            a list and the list of lists is returned
    
fiftyone/core/odm/database.py