Interface Aggregation<A>

interface Aggregation<A> {
    [toStringTag]: string;
    catch: (<TResult>(onrejected?: null | ((reason: any) => TResult | PromiseLike<TResult>)) => Promise<A[] | TResult>);
    finally: ((onfinally?: null | (() => void)) => Promise<A[]>);
    options: AggregateOptions;
    then: (<TResult1, TResult2>(onfulfilled?: null | ((value: A[]) => TResult1 | PromiseLike<TResult1>), onrejected?: null | ((reason: any) => TResult2 | PromiseLike<TResult2>)) => 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>(options?: Record<string, unknown>): Cursor<DocType, never>;
    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: any;
        } | {
            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: FilterQuery<any>): this;
    model(model: Model<any, {}, {}, {}, any, any>): Aggregate<A[]>;
    model(): CustomModel<any, unknown, unknown, unknown, any, 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: {
        [field: string]: AnyExpression | Expression | Project["$project"];
    }): 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: null | ClientSession): 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

Properties

[toStringTag]: string
catch: (<TResult>(onrejected?: null | ((reason: any) => TResult | PromiseLike<TResult>)) => 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>(onrejected?): Promise<A[] | TResult>
    • Attaches a callback for only the rejection of the Promise.

      Type Parameters

      • TResult = never

      Parameters

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

        The callback to execute when the Promise is rejected.

      Returns Promise<A[] | TResult>

      A Promise for the completion of the callback.

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

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

Type declaration

    • (onfinally?): 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: null | (() => void)

        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, TResult2>(onfulfilled?: null | ((value: A[]) => TResult1 | PromiseLike<TResult1>), onrejected?: null | ((reason: any) => TResult2 | PromiseLike<TResult2>)) => Promise<TResult1 | TResult2>)

Provides promise for aggregate.

Type declaration

    • <TResult1, TResult2>(onfulfilled?, onrejected?): Promise<TResult1 | TResult2>
    • Attaches callbacks for the resolution and/or rejection of the Promise.

      Type Parameters

      • TResult1 = A[]
      • TResult2 = never

      Parameters

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

        The callback to execute when the Promise is resolved.

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

        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

    • Rest...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, never>

  • 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";
          };
      }
      • field: string
      • OptionalpartitionByFields?: string[]
      • range: {
            bounds:
                | number[]
                | Date[]
                | "full"
                | "partition";
            step: number;
            unit?:
                | "millisecond"
                | "second"
                | "minute"
                | "hour"
                | "day"
                | "week"
                | "month"
                | "quarter"
                | "year";
        }
        • bounds:
              | number[]
              | Date[]
              | "full"
              | "partition"
        • step: number
        • Optionalunit?:
              | "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>

  • 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: any;
          } | {
              method: "linear" | "locf";
          }>;
          partitionBy?: any;
          partitionByFields?: string[];
          sortBy?: Record<string, -1 | 1>;
      }
      • output: Record<string, {
            value: any;
        } | {
            method: "linear" | "locf";
        }>
      • OptionalpartitionBy?: any
      • OptionalpartitionByFields?: string[]
      • OptionalsortBy?: 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;
      }
      • as: string
      • connectFromField: string
      • connectToField: string
      • OptionaldepthField?: string
      • from: string
      • OptionalmaxDepth?: number
      • OptionalrestrictSearchWithMatch?: 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)[];
      }
      • as: string
      • OptionalforeignField?: string
      • from: string
      • Optionallet?: Record<string, any>
      • OptionallocalField?: string
      • Optionalpipeline?: (
            | 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: FilterQuery<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: {
          [field: string]: AnyExpression | Expression | Project["$project"];
      }
      • [field: string]: AnyExpression | Expression | Project["$project"]

    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;
      }
      • [operator: string]: any
      • Optionalhighlight?: {
            maxCharsToExamine?: number;
            maxNumPassages?: number;
            path: string | string[] | {
                multi: string;
                value: string;
            };
        }
        • OptionalmaxCharsToExamine?: number
        • OptionalmaxNumPassages?: number
        • path: string | string[] | {
              multi: string;
              value: string;
          }
      • Optionalindex?: string

    Returns this

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

    Parameters

    • session: null | ClientSession

    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

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

    Returns this