Interface Aggregation<T>

Type Parameters:
T - The initial type of the aggregation. Used for collection name resolution.

public interface Aggregation<T>
Since:
2.0
  • Method Details

    • pipeline

      Aggregation<T> pipeline(Stage... stages)
      Appends the stages to this aggregation's pipeline.
      Parameters:
      stages - the stages to add
      Returns:
      this
      Since:
      3.0
    • execute

      void execute()
      Execute the aggregation. This form and execute(AggregationOptions) should be used for pipelines with $out and $merge that do no expect any results to be returned.
      See Also:
    • execute

      <S> MorphiaCursor<S> execute(Class<S> resultType)
      Execute the aggregation and get the results.
      Type Parameters:
      S - the output type
      Parameters:
      resultType - the type of the result
      Returns:
      a MorphiaCursor
    • execute

      void execute(AggregationOptions options)
      Execute the aggregation. This form and execute() should be used for pipelines with $out and $merge that do no expect any results to be returned.
      See Also:
    • execute

      <S> MorphiaCursor<S> execute(Class<S> resultType, AggregationOptions options)
      Execute the aggregation and get the results.
      Type Parameters:
      S - the output type
      Parameters:
      resultType - the type of the result
      options - the options to apply
      Returns:
      a MorphiaCursor
    • merge

      <M> void merge(Merge<M> merge)
      Writes the results of the aggregation pipeline to a specified collection. The $merge operator must be the last stage in the pipeline.
      Type Parameters:
      M - the output collection type
      Parameters:
      merge - the merge definition
      MongoDB documentation
      Aggregration Pipeline Stage: $merge
      Since server release
      4.2
    • merge

      <M> void merge(Merge<M> merge, AggregationOptions options)
      Writes the results of the aggregation pipeline to a specified collection. The $merge operator must be the last stage in the pipeline.
      Type Parameters:
      M - the output collection type
      Parameters:
      merge - the merge definition
      options - the options to apply
      MongoDB documentation
      Aggregration Pipeline Stage: $merge
      Since server release
      3.4
    • out

      <O> void out(Out<O> out)
      Writes the results of the aggregation pipeline to a specified collection. The $out operator must be the last stage in the pipeline.
      Type Parameters:
      O - the output collection type
      Parameters:
      out - the out definition
      MongoDB documentation
      Aggregration Pipeline Stage: $out
    • out

      <O> void out(Out<O> out, AggregationOptions options)
      Writes the results of the aggregation pipeline to a specified collection. The $out operator must be the last stage in the pipeline.
      Type Parameters:
      O - the output collection type
      Parameters:
      out - the out definition
      options - the options to apply
      MongoDB documentation
      Aggregration Pipeline Stage: $out
    • autoBucket

      Aggregation<T> autoBucket(AutoBucket bucket)
      Deprecated.
      use pipeline(Stage...) instead
      Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically determined in an attempt to evenly distribute the documents into the specified number of buckets.

      Each bucket is represented as a document in the output. The document for each bucket contains an _id field, whose value specifies the inclusive lower bound and the exclusive upper bound for the bucket, and a count field that contains the number of documents in the bucket. The count field is included by default when the output is not specified.

      Parameters:
      bucket - the bucket definition
      Returns:
      this
      See Also:
    • bucket

      Aggregation<T> bucket(Bucket bucket)
      Deprecated.
      use pipeline(Stage...) instead
      Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.

      Each bucket is represented as a document in the output. The document for each bucket contains an _id field, whose value specifies the inclusive lower bound of the bucket and a count field that contains the number of documents in the bucket. The count field is included by default when the output is not specified.

      $bucket only produces output documents for buckets that contain at least one input document.

      Parameters:
      bucket - the bucket definition
      Returns:
      this
      See Also:
    • collStats

      Aggregation<T> collStats(CollectionStats stats)
      Deprecated.
      use pipeline(Stage...) instead
      Returns statistics regarding a collection or view.
      Parameters:
      stats - the stats configuration
      Returns:
      this
      See Also:
    • count

      Aggregation<T> count(String name)
      Deprecated.
      use pipeline(Stage...) instead
      Passes a document to the next stage that contains a count of the number of documents input to the stage.
      Parameters:
      name - the field name for the resulting count value
      Returns:
      this
      See Also:
      Since server release
      3.4
    • currentOp

      Aggregation<T> currentOp(CurrentOp currentOp)
      Deprecated.
      use pipeline(Stage...) instead
      Returns a stream of documents containing information on active and/or dormant operations as well as inactive sessions that are holding locks as part of a transaction. The stage returns a document for each operation or session. To run $currentOp, use the db.aggregate() helper on the admin database.

      The $currentOp aggregation stage is preferred over the currentOp command and its mongo shell helper db.currentOp(). Because currentOp command and db.currentOp() helper returns the results in a single document, the total size of the currentOp result set is subject to the maximum 16MB BSON size limit for documents. The $currentOp stage returns a cursor over a stream of documents, each of which reports a single operation. Each operation document is subject to the 16MB BSON limit, but unlike the currentOp command, there is no limit on the overall size of the result set.

      $currentOp also enables you to perform arbitrary transformations of the results as the documents pass through the pipeline.

      Parameters:
      currentOp - the configuration
      Returns:
      this
      See Also:
    • densify

      Aggregation<T> densify(Densify densify)
      Deprecated.
      use pipeline(Stage...) instead
      Creates new documents in a sequence of documents where certain values in a field are missing.
      Parameters:
      densify - the Densify stage
      Returns:
      this
      Since:
      2.3
      See Also:
    • documents

      Aggregation<T> documents(DocumentExpression... documents)
      Deprecated.
      use pipeline(Stage...) instead
      Returns literal documents from input values.
      Parameters:
      documents - the documents to use
      Returns:
      this
      Since:
      2.3
      See Also:
    • facet

      Aggregation<T> facet(Facet facet)
      Deprecated.
      use pipeline(Stage...) instead
      Processes multiple aggregation pipelines within a single stage on the same set of input documents. Each sub-pipeline has its own field in the output document where its results are stored as an array of documents.

      The $facet stage allows you to create multi-faceted aggregations which characterize data across multiple dimensions, or facets, within a single aggregation stage. Multi-faceted aggregations provide multiple filters and categorizations to guide data browsing and analysis. Retailers commonly use faceting to narrow search results by creating filters on product price, manufacturer, size, etc.

      Input documents are passed to the $facet stage only once. $facet enables various aggregations on the same set of input documents, without needing to retrieve the input documents multiple times.

      Parameters:
      facet - the facet definition
      Returns:
      this
      See Also:
    • fill

      Aggregation<T> fill(Fill fill)
      Deprecated.
      use pipeline(Stage...) instead
      Populates null and missing field values within documents.

      You can use $fill to populate missing data points:

      • In a sequence based on surrounding values.
      • With a fixed value.
      Parameters:
      fill - the fill definition
      Returns:
      this
      Since:
      2.3
      See Also:
    • geoNear

      Aggregation<T> geoNear(GeoNear near)
      Deprecated.
      use pipeline(Stage...) instead
      Outputs documents in order of nearest to farthest from a specified point.
      Parameters:
      near - the geo query definition
      Returns:
      this
      See Also:
    • graphLookup

      Aggregation<T> graphLookup(GraphLookup lookup)
      Deprecated.
      use pipeline(Stage...) instead
      Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.
      Parameters:
      lookup - the lookup configuration
      Returns:
      this
      See Also:
    • group

      Aggregation<T> group(Group group)
      Deprecated.
      use pipeline(Stage...) instead
      Groups input documents by the specified _id expression and for each distinct grouping, outputs a document. The _id field of each output document contains the unique group by value. The output documents can also contain computed fields that hold the values of some accumulator expression.
      Parameters:
      group - the group definition
      Returns:
      this
      See Also:
    • indexStats

      Aggregation<T> indexStats()
      Deprecated.
      use pipeline(Stage...) instead
      Returns statistics regarding the use of each index for the collection. If running with access control, the user must have privileges that include indexStats action.
      Returns:
      this
      See Also:
    • limit

      Aggregation<T> limit(long limit)
      Deprecated.
      use pipeline(Stage...) instead
      Limits the number of documents passed to the next stage in the pipeline.
      Parameters:
      limit - the maximum docs to pass along to the next stage
      Returns:
      this
      See Also:
    • lookup

      Aggregation<T> lookup(Lookup lookup)
      Deprecated.
      use pipeline(Stage...) instead
      Performs a left outer join to an unsharded collection in the same database to filter in documents from the “joined” collection for processing. To each input document, the $lookup stage adds a new array field whose elements are the matching documents from the “joined” collection. The $lookup stage passes these reshaped documents to the next stage.
      Parameters:
      lookup - the lookup definition
      Returns:
      this
      See Also:
    • match

      Aggregation<T> match(Filter... filters)
      Deprecated.
      use pipeline(Stage...) instead
      Filters the document stream to allow only matching documents to pass unmodified into the next pipeline stage. $match uses standard MongoDB queries. For each input document, outputs either one document (a match) or zero documents (no match).
      Parameters:
      filters - the filters to use when matching
      Returns:
      this
      See Also:
    • planCacheStats

      Aggregation<T> planCacheStats()
      Deprecated.
      use pipeline(Stage...) instead
      Returns plan cache information for a collection. The stage returns a document for each plan cache entry.
      Returns:
      this
      See Also:
    • project

      Aggregation<T> project(Projection projection)
      Deprecated.
      use pipeline(Stage...) instead
      Passes along the documents with the requested fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields.
      Parameters:
      projection - the project definition
      Returns:
      this
      See Also:
    • redact

      Aggregation<T> redact(Redact redact)
      Deprecated.
      use pipeline(Stage...) instead
      Restricts the contents of the documents based on information stored in the documents themselves.
      Parameters:
      redact - the redaction definition
      Returns:
      this
      See Also:
    • replaceRoot

      Aggregation<T> replaceRoot(ReplaceRoot root)
      Deprecated.
      use pipeline(Stage...) instead
      Replaces the input document with the specified document. The operation replaces all existing fields in the input document, including the _id field. You can promote an existing embedded document to the top level, or create a new document for promotion
      Parameters:
      root - the new root definition
      Returns:
      this
      See Also:
    • replaceWith

      Aggregation<T> replaceWith(ReplaceWith with)
      Deprecated.
      use pipeline(Stage...) instead
      Replaces the input document with the specified document. The operation replaces all existing fields in the input document, including the _id field. With $replaceWith, you can promote an embedded document to the top-level. You can also specify a new document as the replacement.

      The $replaceWith is an alias for $replaceRoot.

      Parameters:
      with - the replacement definition
      Returns:
      this
      See Also:
    • sample

      Aggregation<T> sample(long sample)
      Deprecated.
      use pipeline(Stage...) instead
      Randomly selects the specified number of documents from the previous pipeline stage.
      Parameters:
      sample - the sample definition
      Returns:
      this
      See Also:
    • addFields

      @Deprecated(since="3.0", forRemoval=true) Aggregation<T> addFields(AddFields fields)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use pipeline(Stage...) instead
      Adds new fields to documents. $addFields outputs documents that contain all existing fields from the input documents and newly added fields.

      The $addFields stage is equivalent to a $project stage that explicitly specifies all existing fields in the input documents and adds the new fields.

      Parameters:
      fields - the stage definition
      Returns:
      this
      See Also:
    • set

      Aggregation<T> set(Set set)
      Deprecated.
      use pipeline(Stage...) instead
      Adds new fields to documents. $set outputs documents that contain all existing fields from the input documents and newly added fields.

      The $set stage is an alias for $addFields.

      Both stages are equivalent to a $project stage that explicitly specifies all existing fields in the input documents and adds the new fields.

      Parameters:
      set - the stage to add
      Returns:
      this
      Since:
      2.3
      See Also:
    • setWindowFields

      Aggregation<T> setWindowFields(SetWindowFields fields)
      Deprecated.
      use pipeline(Stage...) instead
      Parameters:
      fields - the window fields
      Returns:
      this
      Since:
      2.3
      See Also:
    • skip

      Aggregation<T> skip(long skip)
      Deprecated.
      use pipeline(Stage...) instead
      Skips over the specified number of documents that pass into the stage and passes the remaining documents to the next stage in the pipeline.
      Parameters:
      skip - the skip definition
      Returns:
      this
      See Also:
    • sort

      Aggregation<T> sort(Sort sort)
      Deprecated.
      use pipeline(Stage...) instead
      Sorts all input documents and returns them to the pipeline in sorted order.
      Parameters:
      sort - the sort definition
      Returns:
      this
      See Also:
    • sortByCount

      Aggregation<T> sortByCount(Expression sort)
      Deprecated.
      use pipeline(Stage...) instead
      Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.

      Each output document contains two fields: an _id field containing the distinct grouping value, and a count field containing the number of documents belonging to that grouping or category.

      The documents are sorted by count in descending order.

      Parameters:
      sort - the sort definition
      Returns:
      this
      See Also:
    • unionWith

      Aggregation<T> unionWith(Class<?> type, Stage... stages)
      Deprecated.
      use pipeline(Stage...) instead
      Performs a union of two collections; i.e. $unionWith combines pipeline results from two collections into a single result set. The stage outputs the combined result set (including duplicates) to the next stage.
      Parameters:
      type - the type to perform the pipeline against
      stages - the pipeline stages
      Returns:
      this
      Since:
      2.1
      See Also:
    • unionWith

      Aggregation<T> unionWith(String collection, Stage... stages)
      Deprecated.
      use pipeline(Stage...) instead
      Performs a union of two collections; i.e. $unionWith combines pipeline results from two collections into a single result set. The stage outputs the combined result set (including duplicates) to the next stage.
      Parameters:
      collection - the collection to perform the pipeline against
      stages - the pipeline stages
      Returns:
      this
      Since:
      2.1
      See Also:
      MongoDB documentation
      Aggregration Pipeline Stage: $unionWith
      Since server release
      4.4
    • unset

      Aggregation<T> unset(Unset unset)
      Deprecated.
      use pipeline(Stage...) instead
      Removes/excludes fields from documents. Names must not start with '$'.
      Parameters:
      unset - the unset definition
      Returns:
      this
      See Also:
    • unwind

      Aggregation<T> unwind(Unwind unwind)
      Deprecated.
      use pipeline(Stage...) instead
      Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element.
      Parameters:
      unwind - the unwind definition
      Returns:
      this
      See Also:
    • changeStream

      Aggregation changeStream()
      Deprecated.
      use pipeline(Stage...) instead
      Returns a Change Stream cursor on a collection, a database, or an entire cluster. Must be used as the first stage in an aggregation pipeline.
      Returns:
      this
      Since:
      2.3
      See Also:
    • changeStream

      Aggregation changeStream(ChangeStream stream)
      Deprecated.
      use pipeline(Stage...) instead
      Returns a Change Stream cursor on a collection, a database, or an entire cluster. Must be used as the first stage in an aggregation pipeline.
      Parameters:
      stream - the options to apply to the stage
      Returns:
      this
      Since:
      2.3
      See Also: