public class Aggregation extends Object
Aggregation is a representation of a list of aggregation steps to be performed by the MongoDB Aggregation
Framework.| Modifier and Type | Field and Description |
|---|---|
static String |
CURRENT
References the start of the field path being processed in the aggregation pipeline stage.
|
static AggregationOperationContext |
DEFAULT_CONTEXT |
static AggregationOptions |
DEFAULT_OPTIONS |
protected List<AggregationOperation> |
operations |
static String |
ROOT
References the root document, i.e. the top-level document, currently being processed in the aggregation pipeline
stage.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Aggregation(AggregationOperation... aggregationOperations)
Creates a new
Aggregation from the given AggregationOperations. |
protected |
Aggregation(List<AggregationOperation> aggregationOperations)
Creates a new
Aggregation from the given AggregationOperations. |
protected |
Aggregation(List<AggregationOperation> aggregationOperations,
AggregationOptions options)
Creates a new
Aggregation from the given AggregationOperations. |
| Modifier and Type | Method and Description |
|---|---|
protected static List<AggregationOperation> |
asAggregationList(AggregationOperation... aggregationOperations) |
static Fields |
bind(String name,
String target)
Creates a new
Fields instance from the given field name and target reference. |
static Fields |
fields(String... fields)
Creates a new
Fields instance for the given field names. |
static GeoNearOperation |
geoNear(NearQuery query,
String distanceField)
|
static GroupOperation |
group(Fields fields)
Creates a new
GroupOperation for the given Fields. |
static GroupOperation |
group(String... fields)
Creates a new
GroupOperation for the given fields. |
static LimitOperation |
limit(long maxElements)
Creates a new
LimitOperation limiting the result to the given number of elements. |
static MatchOperation |
match(Criteria criteria)
Creates a new
MatchOperation using the given Criteria. |
static Aggregation |
newAggregation(AggregationOperation... operations)
Creates a new
Aggregation from the given AggregationOperations. |
static <T> TypedAggregation<T> |
newAggregation(Class<T> type,
AggregationOperation... operations)
Creates a new
TypedAggregation for the given type and AggregationOperations. |
static <T> TypedAggregation<T> |
newAggregation(Class<T> type,
List<? extends AggregationOperation> operations)
Creates a new
TypedAggregation for the given type and AggregationOperations. |
static Aggregation |
newAggregation(List<? extends AggregationOperation> operations)
Creates a new
Aggregation from the given AggregationOperations. |
static AggregationOptions.Builder |
newAggregationOptions()
Returns a new
AggregationOptions.Builder. |
static String |
previousOperation()
A pointer to the previous
AggregationOperation. |
static ProjectionOperation |
project(Fields fields)
Creates a new
ProjectionOperation includeing the given Fields. |
static ProjectionOperation |
project(String... fields)
Creates a new
ProjectionOperation including the given fields. |
static SkipOperation |
skip(int elementsToSkip)
Creates a new
SkipOperation skipping the given number of elements. |
static SortOperation |
sort(Sort.Direction direction,
String... fields)
|
static SortOperation |
sort(Sort sort)
Factory method to create a new
SortOperation for the given Sort. |
com.mongodb.DBObject |
toDbObject(String inputCollectionName,
AggregationOperationContext rootContext)
Converts this
Aggregation specification to a DBObject. |
String |
toString() |
static UnwindOperation |
unwind(String field)
Factory method to create a new
UnwindOperation for the field with the given name. |
Aggregation |
withOptions(AggregationOptions options)
Returns a copy of this
Aggregation with the given AggregationOptions set. |
public static final String ROOT
public static final String CURRENT
public static final AggregationOperationContext DEFAULT_CONTEXT
public static final AggregationOptions DEFAULT_OPTIONS
protected final List<AggregationOperation> operations
protected Aggregation(AggregationOperation... aggregationOperations)
Aggregation from the given AggregationOperations.aggregationOperations - must not be null or empty.protected Aggregation(List<AggregationOperation> aggregationOperations)
Aggregation from the given AggregationOperations.aggregationOperations - must not be null or empty.protected Aggregation(List<AggregationOperation> aggregationOperations, AggregationOptions options)
Aggregation from the given AggregationOperations.aggregationOperations - must not be null or empty.options - must not be null or empty.public static Aggregation newAggregation(List<? extends AggregationOperation> operations)
Aggregation from the given AggregationOperations.operations - must not be null or empty.public static Aggregation newAggregation(AggregationOperation... operations)
Aggregation from the given AggregationOperations.operations - must not be null or empty.public Aggregation withOptions(AggregationOptions options)
Aggregation with the given AggregationOptions set. Note that options are
supported in MongoDB version 2.6+.options - must not be null.public static <T> TypedAggregation<T> newAggregation(Class<T> type, List<? extends AggregationOperation> operations)
TypedAggregation for the given type and AggregationOperations.type - must not be null.operations - must not be null or empty.public static <T> TypedAggregation<T> newAggregation(Class<T> type, AggregationOperation... operations)
TypedAggregation for the given type and AggregationOperations.type - must not be null.operations - must not be null or empty.protected static List<AggregationOperation> asAggregationList(AggregationOperation... aggregationOperations)
aggregationOperations - must not be null or empty.public static String previousOperation()
AggregationOperation.public static ProjectionOperation project(String... fields)
ProjectionOperation including the given fields.fields - must not be null.public static ProjectionOperation project(Fields fields)
ProjectionOperation includeing the given Fields.fields - must not be null.public static UnwindOperation unwind(String field)
UnwindOperation for the field with the given name.fieldName - must not be null or empty.public static GroupOperation group(String... fields)
GroupOperation for the given fields.fields - must not be null.public static GroupOperation group(Fields fields)
GroupOperation for the given Fields.fields - must not be null.public static SortOperation sort(Sort sort)
SortOperation for the given Sort.sort - must not be null.public static SortOperation sort(Sort.Direction direction, String... fields)
direction - must not be null.fields - must not be null.public static SkipOperation skip(int elementsToSkip)
SkipOperation skipping the given number of elements.elementsToSkip - must not be less than zero.public static LimitOperation limit(long maxElements)
LimitOperation limiting the result to the given number of elements.maxElements - must not be less than zero.public static MatchOperation match(Criteria criteria)
MatchOperation using the given Criteria.criteria - must not be null.public static Fields fields(String... fields)
Fields instance for the given field names.fields - must not be null.Fields.fields(String...)public static Fields bind(String name, String target)
Fields instance from the given field name and target reference.name - must not be null or empty.target - must not be null or empty.public static GeoNearOperation geoNear(NearQuery query, String distanceField)
GeoNearOperation instance from the given NearQuery and thedistanceField. The
distanceField defines output field that contains the calculated distance.query - must not be null.distanceField - must not be null or empty.public static AggregationOptions.Builder newAggregationOptions()
AggregationOptions.Builder.public com.mongodb.DBObject toDbObject(String inputCollectionName, AggregationOperationContext rootContext)
Aggregation specification to a DBObject.inputCollectionName - the name of the input collectionDBObject representing this aggregationCopyright © 2011-2014–2015 Pivotal Software, Inc.. All rights reserved.