Class AggregationImpl<T>
- java.lang.Object
-
- dev.morphia.aggregation.AggregationImpl<T>
-
- Type Parameters:
T
-
- All Implemented Interfaces:
Aggregation<T>
@MorphiaInternal public class AggregationImpl<T> extends Object implements Aggregation<T>
- Since:
- 2.0
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
-
Constructor Summary
Constructors Constructor Description AggregationImpl(DatastoreImpl datastore, MongoCollection<T> collection)
Creates an instance.AggregationImpl(DatastoreImpl datastore, Class<T> source, MongoCollection<T> collection)
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Aggregation<T>
addFields(AddFields fields)
Adds new fields to documents.Aggregation<T>
addStage(Stage stage)
Adds a custom stage to this pipeline.Aggregation<T>
autoBucket(AutoBucket bucket)
Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression.Aggregation<T>
bucket(Bucket bucket)
Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.Aggregation<T>
changeStream()
Returns a Change Stream cursor on a collection, a database, or an entire cluster.Aggregation<T>
changeStream(ChangeStream stream)
Returns a Change Stream cursor on a collection, a database, or an entire cluster.Aggregation<T>
collStats(CollectionStats stats)
Returns statistics regarding a collection or view.Aggregation<T>
count(String name)
Passes a document to the next stage that contains a count of the number of documents input to the stage.Aggregation<T>
currentOp(CurrentOp currentOp)
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.Aggregation<T>
densify(Densify densify)
Creates new documents in a sequence of documents where certain values in a field are missing.Aggregation<T>
documents(dev.morphia.aggregation.expressions.impls.DocumentExpression... documents)
Returns literal documents from input values.<R> dev.morphia.query.internal.MorphiaCursor<R>
execute(Class<R> resultType)
Execute the aggregation and get the results.<R> dev.morphia.query.internal.MorphiaCursor<R>
execute(Class<R> resultType, AggregationOptions options)
Execute the aggregation and get the results.Aggregation<T>
facet(Facet facet)
Processes multiple aggregation pipelines within a single stage on the same set of input documents.Aggregation<T>
fill(Fill fill)
Populates null and missing field values within documents.Aggregation<T>
geoNear(GeoNear near)
Outputs documents in order of nearest to farthest from a specified point.List<Stage>
getStages()
Aggregation<T>
graphLookup(GraphLookup lookup)
Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.Aggregation<T>
group(Group group)
Groups input documents by the specified _id expression and for each distinct grouping, outputs a document.Aggregation<T>
indexStats()
Returns statistics regarding the use of each index for the collection.Aggregation<T>
limit(long limit)
Limits the number of documents passed to the next stage in the pipeline.Aggregation<T>
lookup(Lookup lookup)
Performs a left outer join to an unsharded collection in the same database to filter in documents from the “joined” collection for processing.Aggregation<T>
match(Filter... filters)
Filters the document stream to allow only matching documents to pass unmodified into the next pipeline stage.<M> void
merge(Merge<M> merge)
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
out(Out<O> out)
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.List<Document>
pipeline()
Aggregation<T>
planCacheStats()
Returns plan cache information for a collection.Aggregation<T>
project(Projection projection)
Passes along the documents with the requested fields to the next stage in the pipeline.Aggregation<T>
redact(Redact redact)
Restricts the contents of the documents based on information stored in the documents themselves.Aggregation<T>
replaceRoot(ReplaceRoot root)
Replaces the input document with the specified document.Aggregation<T>
replaceWith(ReplaceWith with)
Replaces the input document with the specified document.Aggregation<T>
sample(long sample)
Randomly selects the specified number of documents from the previous pipeline stage.Aggregation<T>
set(Set set)
Adds new fields to documents.Aggregation<T>
setWindowFields(SetWindowFields fields)
Aggregation<T>
skip(long skip)
Skips over the specified number of documents that pass into the stage and passes the remaining documents to the next stage in the pipeline.Aggregation<T>
sort(Sort sort)
Sorts all input documents and returns them to the pipeline in sorted order.Aggregation<T>
sortByCount(dev.morphia.aggregation.expressions.impls.Expression sort)
Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.Aggregation<T>
unionWith(Class<?> type, Stage first, Stage... others)
Performs a union of two collections; i.e.Aggregation<T>
unionWith(String collection, Stage first, Stage... others)
Performs a union of two collections; i.e.Aggregation<T>
unset(Unset unset)
Removes/excludes fields from documents.Aggregation<T>
unwind(Unwind unwind)
Deconstructs an array field from the input documents to output a document for each element.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface dev.morphia.aggregation.Aggregation
set
-
-
-
-
Constructor Detail
-
AggregationImpl
@MorphiaInternal public AggregationImpl(DatastoreImpl datastore, MongoCollection<T> collection)
Creates an instance.- Parameters:
datastore
- the datastorecollection
- the source collection
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
AggregationImpl
@MorphiaInternal public AggregationImpl(DatastoreImpl datastore, Class<T> source, MongoCollection<T> collection)
Creates an instance.- Parameters:
datastore
- the datastoresource
- the source typecollection
- the source collection
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
-
Method Detail
-
autoBucket
public Aggregation<T> autoBucket(AutoBucket bucket)
Description copied from interface:Aggregation
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.
- Specified by:
autoBucket
in interfaceAggregation<T>
- Parameters:
bucket
- the bucket definition- Returns:
- this
-
bucket
public Aggregation<T> bucket(Bucket bucket)
Description copied from interface:Aggregation
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.
- Specified by:
bucket
in interfaceAggregation<T>
- Parameters:
bucket
- the bucket definition- Returns:
- this
-
collStats
public Aggregation<T> collStats(CollectionStats stats)
Description copied from interface:Aggregation
Returns statistics regarding a collection or view.- Specified by:
collStats
in interfaceAggregation<T>
- Parameters:
stats
- the stats configuration- Returns:
- this
-
count
public Aggregation<T> count(String name)
Description copied from interface:Aggregation
Passes a document to the next stage that contains a count of the number of documents input to the stage.- Specified by:
count
in interfaceAggregation<T>
- Parameters:
name
- the field name for the resulting count value- Returns:
- this
-
currentOp
public Aggregation<T> currentOp(CurrentOp currentOp)
Description copied from interface:Aggregation
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.
- Specified by:
currentOp
in interfaceAggregation<T>
- Parameters:
currentOp
- the configuration- Returns:
- this
-
densify
public Aggregation<T> densify(Densify densify)
Description copied from interface:Aggregation
Creates new documents in a sequence of documents where certain values in a field are missing.- Specified by:
densify
in interfaceAggregation<T>
- Parameters:
densify
- the Densify stage- Returns:
- this
-
documents
public Aggregation<T> documents(dev.morphia.aggregation.expressions.impls.DocumentExpression... documents)
Description copied from interface:Aggregation
Returns literal documents from input values.- Specified by:
documents
in interfaceAggregation<T>
- Parameters:
documents
- the documents to use- Returns:
- this
-
execute
public <R> dev.morphia.query.internal.MorphiaCursor<R> execute(Class<R> resultType)
Description copied from interface:Aggregation
Execute the aggregation and get the results.- Specified by:
execute
in interfaceAggregation<T>
- Type Parameters:
R
- the output type- Parameters:
resultType
- the type of the result- Returns:
- a MorphiaCursor
-
execute
public <R> dev.morphia.query.internal.MorphiaCursor<R> execute(Class<R> resultType, AggregationOptions options)
Description copied from interface:Aggregation
Execute the aggregation and get the results.- Specified by:
execute
in interfaceAggregation<T>
- Type Parameters:
R
- the output type- Parameters:
resultType
- the type of the resultoptions
- the options to apply- Returns:
- a MorphiaCursor
-
facet
public Aggregation<T> facet(Facet facet)
Description copied from interface:Aggregation
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.
- Specified by:
facet
in interfaceAggregation<T>
- Parameters:
facet
- the facet definition- Returns:
- this
-
fill
public Aggregation<T> fill(Fill fill)
Description copied from interface:Aggregation
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.
- Specified by:
fill
in interfaceAggregation<T>
- Parameters:
fill
- the fill definition- Returns:
- this
-
geoNear
public Aggregation<T> geoNear(GeoNear near)
Description copied from interface:Aggregation
Outputs documents in order of nearest to farthest from a specified point.- Specified by:
geoNear
in interfaceAggregation<T>
- Parameters:
near
- the geo query definition- Returns:
- this
-
graphLookup
public Aggregation<T> graphLookup(GraphLookup lookup)
Description copied from interface:Aggregation
Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.- Specified by:
graphLookup
in interfaceAggregation<T>
- Parameters:
lookup
- the lookup configuration- Returns:
- this
-
group
public Aggregation<T> group(Group group)
Description copied from interface:Aggregation
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.- Specified by:
group
in interfaceAggregation<T>
- Parameters:
group
- the group definition- Returns:
- this
-
indexStats
public Aggregation<T> indexStats()
Description copied from interface:Aggregation
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.- Specified by:
indexStats
in interfaceAggregation<T>
- Returns:
- this
-
limit
public Aggregation<T> limit(long limit)
Description copied from interface:Aggregation
Limits the number of documents passed to the next stage in the pipeline.- Specified by:
limit
in interfaceAggregation<T>
- Parameters:
limit
- the maximum docs to pass along to the next stage- Returns:
- this
-
lookup
public Aggregation<T> lookup(Lookup lookup)
Description copied from interface:Aggregation
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.- Specified by:
lookup
in interfaceAggregation<T>
- Parameters:
lookup
- the lookup definition- Returns:
- this
-
match
public Aggregation<T> match(Filter... filters)
Description copied from interface:Aggregation
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).- Specified by:
match
in interfaceAggregation<T>
- Parameters:
filters
- the filters to use when matching- Returns:
- this
-
merge
public <M> void merge(Merge<M> merge)
Description copied from interface:Aggregation
Writes the results of the aggregation pipeline to a specified collection. The $merge operator must be the last stage in the pipeline.- Specified by:
merge
in interfaceAggregation<T>
- Type Parameters:
M
- the output collection type- Parameters:
merge
- the merge definition
-
merge
public <M> void merge(Merge<M> merge, AggregationOptions options)
Description copied from interface:Aggregation
Writes the results of the aggregation pipeline to a specified collection. The $merge operator must be the last stage in the pipeline.- Specified by:
merge
in interfaceAggregation<T>
- Type Parameters:
M
- the output collection type- Parameters:
merge
- the merge definitionoptions
- the options to apply
-
out
public <O> void out(Out<O> out)
Description copied from interface:Aggregation
Writes the results of the aggregation pipeline to a specified collection. The $out operator must be the last stage in the pipeline.- Specified by:
out
in interfaceAggregation<T>
- Type Parameters:
O
- the output collection type- Parameters:
out
- the out definition
-
out
public <O> void out(Out<O> out, AggregationOptions options)
Description copied from interface:Aggregation
Writes the results of the aggregation pipeline to a specified collection. The $out operator must be the last stage in the pipeline.- Specified by:
out
in interfaceAggregation<T>
- Type Parameters:
O
- the output collection type- Parameters:
out
- the out definitionoptions
- the options to apply
-
planCacheStats
public Aggregation<T> planCacheStats()
Description copied from interface:Aggregation
Returns plan cache information for a collection. The stage returns a document for each plan cache entry.- Specified by:
planCacheStats
in interfaceAggregation<T>
- Returns:
- this
-
project
public Aggregation<T> project(Projection projection)
Description copied from interface:Aggregation
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.- Specified by:
project
in interfaceAggregation<T>
- Parameters:
projection
- the project definition- Returns:
- this
-
redact
public Aggregation<T> redact(Redact redact)
Description copied from interface:Aggregation
Restricts the contents of the documents based on information stored in the documents themselves.- Specified by:
redact
in interfaceAggregation<T>
- Parameters:
redact
- the redaction definition- Returns:
- this
-
replaceRoot
public Aggregation<T> replaceRoot(ReplaceRoot root)
Description copied from interface:Aggregation
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- Specified by:
replaceRoot
in interfaceAggregation<T>
- Parameters:
root
- the new root definition- Returns:
- this
-
replaceWith
public Aggregation<T> replaceWith(ReplaceWith with)
Description copied from interface:Aggregation
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.
- Specified by:
replaceWith
in interfaceAggregation<T>
- Parameters:
with
- the replacement definition- Returns:
- this
-
sample
public Aggregation<T> sample(long sample)
Description copied from interface:Aggregation
Randomly selects the specified number of documents from the previous pipeline stage.- Specified by:
sample
in interfaceAggregation<T>
- Parameters:
sample
- the sample definition- Returns:
- this
-
addFields
public Aggregation<T> addFields(AddFields fields)
Description copied from interface:Aggregation
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.
- Specified by:
addFields
in interfaceAggregation<T>
- Parameters:
fields
- the stage definition- Returns:
- this
-
set
public Aggregation<T> set(Set set)
Description copied from interface:Aggregation
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.
- Specified by:
set
in interfaceAggregation<T>
- Parameters:
set
- the stage to add- Returns:
- this
-
setWindowFields
public Aggregation<T> setWindowFields(SetWindowFields fields)
- Specified by:
setWindowFields
in interfaceAggregation<T>
- Returns:
- this
-
skip
public Aggregation<T> skip(long skip)
Description copied from interface:Aggregation
Skips over the specified number of documents that pass into the stage and passes the remaining documents to the next stage in the pipeline.- Specified by:
skip
in interfaceAggregation<T>
- Parameters:
skip
- the skip definition- Returns:
- this
-
sort
public Aggregation<T> sort(Sort sort)
Description copied from interface:Aggregation
Sorts all input documents and returns them to the pipeline in sorted order.- Specified by:
sort
in interfaceAggregation<T>
- Parameters:
sort
- the sort definition- Returns:
- this
-
sortByCount
public Aggregation<T> sortByCount(dev.morphia.aggregation.expressions.impls.Expression sort)
Description copied from interface:Aggregation
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.
- Specified by:
sortByCount
in interfaceAggregation<T>
- Parameters:
sort
- the sort definition- Returns:
- this
-
unionWith
public Aggregation<T> unionWith(Class<?> type, Stage first, Stage... others)
Description copied from interface:Aggregation
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.- Specified by:
unionWith
in interfaceAggregation<T>
- Parameters:
type
- the type to perform the pipeline againstfirst
- the first pipeline stageothers
- the other pipeline stages- Returns:
- this
-
unionWith
public Aggregation<T> unionWith(String collection, Stage first, Stage... others)
Description copied from interface:Aggregation
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.- Specified by:
unionWith
in interfaceAggregation<T>
- Parameters:
collection
- the collection to perform the pipeline againstfirst
- the first pipeline stageothers
- the other pipeline stages- Returns:
- this
-
unset
public Aggregation<T> unset(Unset unset)
Description copied from interface:Aggregation
Removes/excludes fields from documents. Names must not start with '$'.- Specified by:
unset
in interfaceAggregation<T>
- Parameters:
unset
- the unset definition- Returns:
- this
-
unwind
public Aggregation<T> unwind(Unwind unwind)
Description copied from interface:Aggregation
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.- Specified by:
unwind
in interfaceAggregation<T>
- Parameters:
unwind
- the unwind definition- Returns:
- this
-
changeStream
public Aggregation<T> changeStream()
Description copied from interface:Aggregation
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.- Specified by:
changeStream
in interfaceAggregation<T>
- Returns:
- this
-
changeStream
public Aggregation<T> changeStream(ChangeStream stream)
Description copied from interface:Aggregation
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.- Specified by:
changeStream
in interfaceAggregation<T>
- Parameters:
stream
- the options to apply to the stage- Returns:
- this
-
addStage
public Aggregation<T> addStage(Stage stage)
Description copied from interface:Aggregation
Adds a custom stage to this pipeline. Sometimes a new server release comes out with new stages and Morphia can lag sometimes. Using this method, custom stages can be added to fill that gap until Morphia can catch up. This method is marked as internal because while it should remain relatively stable, it may shift as needs evolve and isn't intended for general use.- Specified by:
addStage
in interfaceAggregation<T>
- Parameters:
stage
- the new Stage- Returns:
- this
-
-