Interface Aggregation<T>
- Type Parameters:
T
- The initial type of the aggregation. Used for collection name resolution.
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionDeprecated, for removal: This API element is subject to removal in a future version.autoBucket
(AutoBucket bucket) Deprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadchangeStream
(ChangeStream stream) Deprecated.usepipeline(Stage...)
insteadcollStats
(CollectionStats stats) Deprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteaddocuments
(DocumentExpression... documents) Deprecated.usepipeline(Stage...)
insteadvoid
execute()
Execute the aggregation.void
execute
(AggregationOptions options) Execute the aggregation.<S> MorphiaCursor<S>
Execute the aggregation and get the results.<S> MorphiaCursor<S>
execute
(Class<S> resultType, AggregationOptions options) Execute the aggregation and get the results.Deprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadgraphLookup
(GraphLookup lookup) Deprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadlimit
(long limit) Deprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
instead<M> void
Writes the results of the aggregation pipeline to a specified collection.<M> void
merge
(Merge<M> merge, AggregationOptions options) Writes the results of the aggregation pipeline to a specified collection.<O> void
Writes the results of the aggregation pipeline to a specified collection.<O> void
out
(Out<O> out, AggregationOptions options) Writes the results of the aggregation pipeline to a specified collection.Appends the stages to this aggregation's pipeline.Deprecated.usepipeline(Stage...)
insteadproject
(Projection projection) Deprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadreplaceRoot
(ReplaceRoot root) Deprecated.usepipeline(Stage...)
insteadreplaceWith
(ReplaceWith with) Deprecated.usepipeline(Stage...)
insteadsample
(long sample) Deprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadsetWindowFields
(SetWindowFields fields) Deprecated.usepipeline(Stage...)
insteadskip
(long skip) Deprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadsortByCount
(Expression sort) Deprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
insteadDeprecated.usepipeline(Stage...)
instead
-
Method Details
-
pipeline
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 andexecute(AggregationOptions)
should be used for pipelines with $out and $merge that do not expect any results to be returned.- See Also:
-
execute
Execute the aggregation and get the results.- Type Parameters:
S
- the output type- Parameters:
resultType
- the type of the result- Returns:
- a MorphiaCursor
-
execute
Execute the aggregation. This form andexecute()
should be used for pipelines with $out and $merge that do no expect any results to be returned.- See Also:
-
execute
Execute the aggregation and get the results.- Type Parameters:
S
- the output type- Parameters:
resultType
- the type of the resultoptions
- the options to apply- Returns:
- a MorphiaCursor
-
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
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 definitionoptions
- the options to apply- MongoDB documentation
- Aggregration Pipeline Stage: $merge
- Since server release
- 3.4
-
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
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 definitionoptions
- the options to apply- MongoDB documentation
- Aggregration Pipeline Stage: $out
-
autoBucket
Deprecated.usepipeline(Stage...)
insteadCategorizes 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
Deprecated.usepipeline(Stage...)
insteadCategorizes 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
Deprecated.usepipeline(Stage...)
insteadReturns statistics regarding a collection or view.- Parameters:
stats
- the stats configuration- Returns:
- this
- See Also:
-
count
Deprecated.usepipeline(Stage...)
insteadPasses 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
Deprecated.usepipeline(Stage...)
insteadReturns 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
Deprecated.usepipeline(Stage...)
insteadCreates 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
Deprecated.usepipeline(Stage...)
insteadReturns literal documents from input values.- Parameters:
documents
- the documents to use- Returns:
- this
- Since:
- 2.3
- See Also:
-
facet
Deprecated.usepipeline(Stage...)
insteadProcesses 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
Deprecated.usepipeline(Stage...)
insteadPopulates 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
Deprecated.usepipeline(Stage...)
insteadOutputs documents in order of nearest to farthest from a specified point.- Parameters:
near
- the geo query definition- Returns:
- this
- See Also:
-
graphLookup
Deprecated.usepipeline(Stage...)
insteadPerforms 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
Deprecated.usepipeline(Stage...)
insteadGroups 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.usepipeline(Stage...)
insteadReturns 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
Deprecated.usepipeline(Stage...)
insteadLimits 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
Deprecated.usepipeline(Stage...)
insteadPerforms 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
Deprecated.usepipeline(Stage...)
insteadFilters 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.usepipeline(Stage...)
insteadReturns plan cache information for a collection. The stage returns a document for each plan cache entry.- Returns:
- this
- See Also:
-
project
Deprecated.usepipeline(Stage...)
insteadPasses 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
Deprecated.usepipeline(Stage...)
insteadRestricts the contents of the documents based on information stored in the documents themselves.- Parameters:
redact
- the redaction definition- Returns:
- this
- See Also:
-
replaceRoot
Deprecated.usepipeline(Stage...)
insteadReplaces 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
Deprecated.usepipeline(Stage...)
insteadReplaces 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
Deprecated.usepipeline(Stage...)
insteadRandomly selects the specified number of documents from the previous pipeline stage.- Parameters:
sample
- the sample definition- Returns:
- this
- See Also:
-
addFields
Deprecated, for removal: This API element is subject to removal in a future version.usepipeline(Stage...)
insteadAdds 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
Deprecated.usepipeline(Stage...)
insteadAdds 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
Deprecated.usepipeline(Stage...)
instead- Parameters:
fields
- the window fields- Returns:
- this
- Since:
- 2.3
- See Also:
-
skip
Deprecated.usepipeline(Stage...)
insteadSkips 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
Deprecated.usepipeline(Stage...)
insteadSorts all input documents and returns them to the pipeline in sorted order.- Parameters:
sort
- the sort definition- Returns:
- this
- See Also:
-
sortByCount
Deprecated.usepipeline(Stage...)
insteadGroups 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
Deprecated.usepipeline(Stage...)
insteadPerforms 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 againststages
- the pipeline stages- Returns:
- this
- Since:
- 2.1
- See Also:
-
unionWith
Deprecated.usepipeline(Stage...)
insteadPerforms 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 againststages
- the pipeline stages- Returns:
- this
- Since:
- 2.1
- See Also:
- MongoDB documentation
- Aggregration Pipeline Stage: $unionWith
- Since server release
- 4.4
-
unset
Deprecated.usepipeline(Stage...)
insteadRemoves/excludes fields from documents. Names must not start with '$'.- Parameters:
unset
- the unset definition- Returns:
- this
- See Also:
-
unwind
Deprecated.usepipeline(Stage...)
insteadDeconstructs 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.usepipeline(Stage...)
insteadReturns 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
Deprecated.usepipeline(Stage...)
insteadReturns 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:
-
pipeline(Stage...)
instead