@storehouse/mongoose - v4.0.0
    Preparing search index...

    Interface Aggregation<A>

    interface Aggregation<A = unknown> {
        "[toStringTag]": string;
        catch: <TResult = never>(
            onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null,
        ) => Promise<A[] | TResult>;
        finally: (onfinally?: (() => void) | null) => Promise<A[]>;
        options: AggregateOptions;
        then: <TResult1 = A[], TResult2 = never>(
            onfulfilled?: ((value: A[]) => TResult1 | PromiseLike<TResult1>) | null,
            onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null,
        ) => Promise<TResult1 | TResult2>;
        "[asyncIterator]"(): AsyncIterableIterator<A>;
        addCursorFlag(flag: CursorFlag, value: boolean): this;
        addFields(arg: Record<string, any>): this;
        allowDiskUse(value: boolean): this;
        append(...args: PipelineStage[]): this;
        collation(options: CollationOptions): this;
        count(fieldName: string): this;
        countDocuments(): Promise<number>;
        cursor<DocType = any>(options?: Record<string, unknown>): Cursor<DocType>;
        densify(
            arg: {
                field: string;
                partitionByFields?: string[];
                range: {
                    bounds: number[] | Date[] | "full" | "partition";
                    step: number;
                    unit?:
                        | "millisecond"
                        | "second"
                        | "minute"
                        | "hour"
                        | "day"
                        | "week"
                        | "month"
                        | "quarter"
                        | "year";
                };
            },
        ): this;
        exec(cursorOptions?: Record<string, unknown>): Promise<A[]>;
        explain(verbosity: ExplainVerbosityLike): Promise<AnyObject>;
        explain(): Promise<AnyObject>;
        facet(options: Record<string, FacetPipelineStage[]>): this;
        fill(
            arg: {
                output: Record<
                    string,
                    { value: Expression }
                    | { method: "linear" | "locf" },
                >;
                partitionBy?: any;
                partitionByFields?: string[];
                sortBy?: Record<string, -1 | 1>;
            },
        ): this;
        graphLookup(
            options: {
                as: string;
                connectFromField: string;
                connectToField: string;
                depthField?: string;
                from: string;
                maxDepth?: number;
                restrictSearchWithMatch?: AnyObject;
                startWith: any;
            },
        ): this;
        group(arg: { _id: any } | { [key: string]: AccumulatorOperator }): this;
        hint(value: string | Record<string, unknown>): this;
        limit(num: number): this;
        lookup(
            options: {
                as: string;
                foreignField?: string;
                from: string;
                let?: Record<string, any>;
                localField?: string;
                pipeline?: (
                    | AddFields
                    | Bucket
                    | BucketAuto
                    | CollStats
                    | Count
                    | Densify
                    | Documents
                    | Facet
                    | Fill
                    | GeoNear
                    | GraphLookup
                    | Group
                    | IndexStats
                    | Limit
                    | ListSessions
                    | Lookup
                    | Match
                    | PlanCacheStats
                    | Project
                    | Redact
                    | ReplaceRoot
                    | ReplaceWith
                    | Sample
                    | Search
                    | SearchMeta
                    | Set
                    | SetWindowFields
                    | Skip
                    | Sort
                    | SortByCount
                    | UnionWith
                    | Unset
                    | Unwind
                    | VectorSearch
                )[];
            },
        ): this;
        match(arg: _QueryFilter<Record<string, any>>): this;
        model(model: Model<any>): Aggregate<A[]>;
        model(): CustomModel<any>;
        near(
            arg: {
                distanceField: string;
                distanceMultiplier?: number;
                includeLocs?: string;
                key?: string;
                maxDistance?: number;
                minDistance?: number;
                near: { coordinates: [number, number]; type: "Point" } | [number, number];
                num?: number;
                query?: AnyObject;
                spherical?: boolean;
            },
        ): this;
        option(value: AggregateOptions): this;
        pipeline(): PipelineStage[];
        project(arg: string | { [field: string]: any }): this;
        read(pref: ReadPreferenceLike): this;
        readConcern(level: string): this;
        redact(
            expression: any,
            thenExpr: AnyObject | "$$DESCEND" | "$$PRUNE" | "$$KEEP",
            elseExpr: AnyObject | "$$DESCEND" | "$$PRUNE" | "$$KEEP",
        ): this;
        replaceRoot(newRoot: any): this;
        sample(arg: number): this;
        search(
            options: {
                highlight?: {
                    maxCharsToExamine?: number;
                    maxNumPassages?: number;
                    path: string | string[] | { multi: string; value: string };
                };
                index?: string;
                [operator: string]: any;
            },
        ): this;
        session(session: ClientSession | null): this;
        skip(num: number): this;
        sort(
            arg: string | Record<string, SortOrder> | Record<string, 1 | -1 | Meta>,
        ): this;
        sortByCount(arg: any): this;
        unionWith(
            options:
                | string
                | {
                    coll: string;
                    pipeline?: (
                        | AddFields
                        | Bucket
                        | BucketAuto
                        | CollStats
                        | Count
                        | Densify
                        | Documents
                        | Facet
                        | Fill
                        | GeoNear
                        | GraphLookup
                        | Group
                        | IndexStats
                        | Limit
                        | ListSessions
                        | Lookup
                        | Match
                        | PlanCacheStats
                        | Project
                        | Redact
                        | ReplaceRoot
                        | ReplaceWith
                        | Sample
                        | Search
                        | SearchMeta
                        | Set
                        | SetWindowFields
                        | Skip
                        | Sort
                        | SortByCount
                        | UnionWith
                        | Unset
                        | Unwind
                        | VectorSearch
                    )[];
                }
                | {
                    coll?: string;
                    pipeline: (
                        | AddFields
                        | Bucket
                        | BucketAuto
                        | CollStats
                        | Count
                        | Densify
                        | Documents
                        | Facet
                        | Fill
                        | GeoNear
                        | GraphLookup
                        | Group
                        | IndexStats
                        | Limit
                        | ListSessions
                        | Lookup
                        | Match
                        | PlanCacheStats
                        | Project
                        | Redact
                        | ReplaceRoot
                        | ReplaceWith
                        | Sample
                        | Search
                        | SearchMeta
                        | Set
                        | SetWindowFields
                        | Skip
                        | Sort
                        | SortByCount
                        | UnionWith
                        | Unset
                        | Unwind
                        | VectorSearch
                    )[];
                },
        ): this;
        unwind(
            ...args: (
                | string
                | {
                    includeArrayIndex?: string;
                    path: string;
                    preserveNullAndEmptyArrays?: boolean;
                }
            )[],
        ): this;
        [key: string]: unknown;
    }

    Type Parameters

    • A = unknown

    Hierarchy

    • Omit<ExtendedAggregate<A[]>, "model">
      • Aggregation

    Indexable

    • [key: string]: unknown
    Index

    Properties

    "[toStringTag]": string
    catch: <TResult = never>(
        onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null,
    ) => Promise<A[] | TResult>

    Executes the query returning a Promise which will be resolved with either the doc(s) or rejected with the error. Like .then(), but only takes a rejection handler.

    Type Declaration

      • <TResult = never>(
            onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null,
        ): Promise<A[] | TResult>
      • Attaches a callback for only the rejection of the Promise.

        Type Parameters

        • TResult = never

        Parameters

        • Optionalonrejected: ((reason: any) => TResult | PromiseLike<TResult>) | null

          The callback to execute when the Promise is rejected.

        Returns Promise<A[] | TResult>

        A Promise for the completion of the callback.

    finally: (onfinally?: (() => void) | null) => Promise<A[]>

    Executes the aggregation returning a Promise which will be resolved with .finally() chained.

    Type Declaration

      • (onfinally?: (() => void) | null): Promise<A[]>
      • Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

        Parameters

        • Optionalonfinally: (() => void) | null

          The callback to execute when the Promise is settled (fulfilled or rejected).

        Returns Promise<A[]>

        A Promise for the completion of the callback.

    options: AggregateOptions
    then: <TResult1 = A[], TResult2 = never>(
        onfulfilled?: ((value: A[]) => TResult1 | PromiseLike<TResult1>) | null,
        onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null,
    ) => Promise<TResult1 | TResult2>

    Provides promise for aggregate.

    Type Declaration

      • <TResult1 = A[], TResult2 = never>(
            onfulfilled?: ((value: A[]) => TResult1 | PromiseLike<TResult1>) | null,
            onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null,
        ): Promise<TResult1 | TResult2>
      • Attaches callbacks for the resolution and/or rejection of the Promise.

        Type Parameters

        • TResult1 = A[]
        • TResult2 = never

        Parameters

        • Optionalonfulfilled: ((value: A[]) => TResult1 | PromiseLike<TResult1>) | null

          The callback to execute when the Promise is resolved.

        • Optionalonrejected: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null

          The callback to execute when the Promise is rejected.

        Returns Promise<TResult1 | TResult2>

        A Promise for the completion of which ever callback is executed.

    Methods

    • Returns an asyncIterator for use with for/await/of loops You do not need to call this function explicitly, the JavaScript runtime will call it for you.

      Returns AsyncIterableIterator<A>

    • Sets an option on this aggregation. This function will be deprecated in a future release.

      Parameters

      • flag: CursorFlag
      • value: boolean

      Returns this

    • Appends a new $addFields operator to this aggregate pipeline. Requires MongoDB v3.4+ to work

      Parameters

      • arg: Record<string, any>

      Returns this

    • Sets the allowDiskUse option for the aggregation query

      Parameters

      • value: boolean

      Returns this

    • Appends new operators to this aggregate pipeline

      Parameters

      • ...args: PipelineStage[]

      Returns this

    • Set the collation.

      Parameters

      • options: CollationOptions

      Returns this

    • Appends a new $count operator to this aggregate pipeline.

      Parameters

      • fieldName: string

      Returns this

    • Returns Promise<number>

    • Sets the cursor option for the aggregation query

      Type Parameters

      • DocType = any

      Parameters

      • Optionaloptions: Record<string, unknown>

      Returns Cursor<DocType>

    • Appends a new $densify operator to this aggregate pipeline

      Parameters

      • arg: {
            field: string;
            partitionByFields?: string[];
            range: {
                bounds: number[] | Date[] | "full" | "partition";
                step: number;
                unit?:
                    | "millisecond"
                    | "second"
                    | "minute"
                    | "hour"
                    | "day"
                    | "week"
                    | "month"
                    | "quarter"
                    | "year";
            };
        }

      Returns this

    • Executes the aggregate pipeline on the currently bound Model.

      Parameters

      • OptionalcursorOptions: Record<string, unknown>

      Returns Promise<A[]>

    • Execute the aggregation with explain

      Parameters

      • verbosity: ExplainVerbosityLike

      Returns Promise<AnyObject>

    • Execute the aggregation with explain

      Returns Promise<AnyObject>

    • Combines multiple aggregation pipelines.

      Parameters

      • options: Record<string, FacetPipelineStage[]>

      Returns this

    • Appends a new $fill operator to this aggregate pipeline

      Parameters

      • arg: {
            output: Record<
                string,
                { value: Expression }
                | { method: "linear" | "locf" },
            >;
            partitionBy?: any;
            partitionByFields?: string[];
            sortBy?: Record<string, -1 | 1>;
        }

      Returns this

    • Appends new custom $graphLookup operator(s) to this aggregate pipeline, performing a recursive search on a collection.

      Parameters

      • options: {
            as: string;
            connectFromField: string;
            connectToField: string;
            depthField?: string;
            from: string;
            maxDepth?: number;
            restrictSearchWithMatch?: AnyObject;
            startWith: any;
        }

      Returns this

    • Appends new custom $group operator to this aggregate pipeline.

      Parameters

      • arg: { _id: any } | { [key: string]: AccumulatorOperator }

      Returns this

    • Sets the hint option for the aggregation query

      Parameters

      • value: string | Record<string, unknown>

      Returns this

    • Appends a new $limit operator to this aggregate pipeline.

      Parameters

      • num: number

        maximum number of records to pass to the next stage

      Returns this

    • Appends new custom $lookup operator to this aggregate pipeline.

      Parameters

      • options: {
            as: string;
            foreignField?: string;
            from: string;
            let?: Record<string, any>;
            localField?: string;
            pipeline?: (
                | AddFields
                | Bucket
                | BucketAuto
                | CollStats
                | Count
                | Densify
                | Documents
                | Facet
                | Fill
                | GeoNear
                | GraphLookup
                | Group
                | IndexStats
                | Limit
                | ListSessions
                | Lookup
                | Match
                | PlanCacheStats
                | Project
                | Redact
                | ReplaceRoot
                | ReplaceWith
                | Sample
                | Search
                | SearchMeta
                | Set
                | SetWindowFields
                | Skip
                | Sort
                | SortByCount
                | UnionWith
                | Unset
                | Unwind
                | VectorSearch
            )[];
        }

      Returns this

    • Appends a new custom $match operator to this aggregate pipeline.

      Parameters

      • arg: _QueryFilter<Record<string, any>>

        $match operator contents

      Returns this

    • Appends a new $geoNear operator to this aggregate pipeline.

      Parameters

      • arg: {
            distanceField: string;
            distanceMultiplier?: number;
            includeLocs?: string;
            key?: string;
            maxDistance?: number;
            minDistance?: number;
            near: { coordinates: [number, number]; type: "Point" } | [number, number];
            num?: number;
            query?: AnyObject;
            spherical?: boolean;
        }
        • distanceField: string
        • OptionaldistanceMultiplier?: number
        • OptionalincludeLocs?: string
        • Optionalkey?: string
        • OptionalmaxDistance?: number
        • OptionalminDistance?: number
        • near: { coordinates: [number, number]; type: "Point" } | [number, number]
        • Optionalnum?: number

          Deprecated. Use only with MondoDB below 4.2 (removed in 4.2)

        • Optionalquery?: AnyObject
        • Optionalspherical?: boolean

      Returns this

    • Lets you set arbitrary options, for middlewares or plugins.

      Parameters

      • value: AggregateOptions

      Returns this

    • Returns the current pipeline

      Returns PipelineStage[]

    • Appends a new $project operator to this aggregate pipeline.

      Parameters

      • arg: string | { [field: string]: any }

      Returns this

    • Sets the readPreference option for the aggregation query.

      Parameters

      • pref: ReadPreferenceLike

      Returns this

    • Sets the readConcern level for the aggregation query.

      Parameters

      • level: string

      Returns this

    • Appends a new $redact operator to this aggregate pipeline.

      Parameters

      • expression: any
      • thenExpr: AnyObject | "$$DESCEND" | "$$PRUNE" | "$$KEEP"
      • elseExpr: AnyObject | "$$DESCEND" | "$$PRUNE" | "$$KEEP"

      Returns this

    • Appends a new $replaceRoot operator to this aggregate pipeline.

      Parameters

      • newRoot: any

      Returns this

    • Appends new custom $sample operator to this aggregate pipeline.

      Parameters

      • arg: number

      Returns this

    • Helper for Atlas Text Search's $search stage.

      Parameters

      • options: {
            highlight?: {
                maxCharsToExamine?: number;
                maxNumPassages?: number;
                path: string | string[] | { multi: string; value: string };
            };
            index?: string;
            [operator: string]: any;
        }

      Returns this

    • Sets the session for this aggregation. Useful for transactions.

      Parameters

      • session: ClientSession | null

      Returns this

    • Appends a new $skip operator to this aggregate pipeline.

      Parameters

      • num: number

        number of records to skip before next stage

      Returns this

    • Appends a new $sort operator to this aggregate pipeline.

      Parameters

      • arg: string | Record<string, SortOrder> | Record<string, 1 | -1 | Meta>

      Returns this

    • Appends a new $sortByCount operator to this aggregate pipeline. Accepts either a string field name or a pipeline object.

      Parameters

      • arg: any

      Returns this

    • Appends new $unionWith operator to this aggregate pipeline.

      Parameters

      • options:
            | string
            | {
                coll: string;
                pipeline?: (
                    | AddFields
                    | Bucket
                    | BucketAuto
                    | CollStats
                    | Count
                    | Densify
                    | Documents
                    | Facet
                    | Fill
                    | GeoNear
                    | GraphLookup
                    | Group
                    | IndexStats
                    | Limit
                    | ListSessions
                    | Lookup
                    | Match
                    | PlanCacheStats
                    | Project
                    | Redact
                    | ReplaceRoot
                    | ReplaceWith
                    | Sample
                    | Search
                    | SearchMeta
                    | Set
                    | SetWindowFields
                    | Skip
                    | Sort
                    | SortByCount
                    | UnionWith
                    | Unset
                    | Unwind
                    | VectorSearch
                )[];
            }
            | {
                coll?: string;
                pipeline: (
                    | AddFields
                    | Bucket
                    | BucketAuto
                    | CollStats
                    | Count
                    | Densify
                    | Documents
                    | Facet
                    | Fill
                    | GeoNear
                    | GraphLookup
                    | Group
                    | IndexStats
                    | Limit
                    | ListSessions
                    | Lookup
                    | Match
                    | PlanCacheStats
                    | Project
                    | Redact
                    | ReplaceRoot
                    | ReplaceWith
                    | Sample
                    | Search
                    | SearchMeta
                    | Set
                    | SetWindowFields
                    | Skip
                    | Sort
                    | SortByCount
                    | UnionWith
                    | Unset
                    | Unwind
                    | VectorSearch
                )[];
            }

      Returns this

    • Appends new custom $unwind operator(s) to this aggregate pipeline.

      Parameters

      • ...args: (
            | string
            | {
                includeArrayIndex?: string;
                path: string;
                preserveNullAndEmptyArrays?: boolean;
            }
        )[]

      Returns this