Package dev.morphia.aggregation
Class Group
- java.lang.Object
-
- dev.morphia.aggregation.Group
-
public final class Group extends java.lang.Object
Defines a group pipeline stage.- MongoDB documentation
- reference/operator/aggregation/group/ $group
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Accumulator
addToSet(java.lang.String field)
Returns an array of all unique values that results from applying an expression to each document in a group of documents that share the same group by key.static Accumulator
average(java.lang.String field)
Returns the average value of the numeric values that result from applying a specified expression to each document in a group of documents that share the same group by key.static Accumulator
first(java.lang.String field)
Returns the value that results from applying an expression to the first document in a group of documents that share the same group by key.Accumulator
getAccumulator()
java.lang.String
getName()
Group
getNested()
java.util.List<Projection>
getProjections()
java.lang.String
getSourceField()
static Group
grouping(java.lang.String name)
Creates a named groupingstatic Group
grouping(java.lang.String name, Accumulator accumulator)
Creates a named grouping on a fieldstatic Group
grouping(java.lang.String name, Group group)
Creates a named groupingstatic Group
grouping(java.lang.String name, Projection... projections)
Creates a named groupingstatic Group
grouping(java.lang.String name, java.lang.String sourceField)
Creates a named grouping on a fieldstatic java.util.List<Group>
id(Group... fields)
Create a group of Groups for use as an IDstatic Accumulator
last(java.lang.String field)
Returns the value that results from applying an expression to the last document in a group of documents that share the same group by a field.static Accumulator
max(java.lang.String field)
Returns the highest value that results from applying an expression to each document in a group of documents that share the same group by key.static Accumulator
min(java.lang.String field)
Returns the lowest value that results from applying an expression to each document in a group of documents that share the same group by key.static Accumulator
push(java.lang.String field)
Returns an array of all values that result from applying an expression to each document in a group of documents that share the same group by key.static Accumulator
sum(java.lang.String field)
Calculates and returns the sum of all the numeric values that result from applying a specified expression to each document in a group of documents that share the same group by key.
-
-
-
Method Detail
-
id
public static java.util.List<Group> id(Group... fields)
Create a group of Groups for use as an ID- Parameters:
fields
- the Groups to group- Returns:
- the Group
-
grouping
public static Group grouping(java.lang.String name)
Creates a named grouping- Parameters:
name
- the field name- Returns:
- the Group
-
grouping
public static Group grouping(java.lang.String name, Projection... projections)
Creates a named grouping- Parameters:
name
- the field nameprojections
- the fields to create- Returns:
- the Group
-
grouping
public static Group grouping(java.lang.String name, Group group)
Creates a named grouping- Parameters:
name
- the field namegroup
- the fields to create- Returns:
- the Group
-
grouping
public static Group grouping(java.lang.String name, java.lang.String sourceField)
Creates a named grouping on a field- Parameters:
name
- the group namesourceField
- the field name- Returns:
- the Group
-
grouping
public static Group grouping(java.lang.String name, Accumulator accumulator)
Creates a named grouping on a field- Parameters:
name
- the group nameaccumulator
- the Accumulator to apply to the field- Returns:
- the Group
-
addToSet
public static Accumulator addToSet(java.lang.String field)
Returns an array of all unique values that results from applying an expression to each document in a group of documents that share the same group by key. Order of the elements in the output array is unspecified.- Parameters:
field
- the field to process- Returns:
- an Accumulator
- MongoDB documentation
- reference/operator/aggregation/addToSet $addToSet
-
average
public static Accumulator average(java.lang.String field)
Returns the average value of the numeric values that result from applying a specified expression to each document in a group of documents that share the same group by key. $avg ignores non-numeric values.- Parameters:
field
- the field to process- Returns:
- an Accumulator
- MongoDB documentation
- reference/operator/aggregation/avg $avg
-
first
public static Accumulator first(java.lang.String field)
Returns the value that results from applying an expression to the first document in a group of documents that share the same group by key. Only meaningful when documents are in a defined order.- Parameters:
field
- the field to process- Returns:
- an Accumulator
- MongoDB documentation
- reference/operator/aggregation/first $first
-
last
public static Accumulator last(java.lang.String field)
Returns the value that results from applying an expression to the last document in a group of documents that share the same group by a field. Only meaningful when documents are in a defined order.- Parameters:
field
- the field to process- Returns:
- an Accumulator
- MongoDB documentation
- reference/operator/aggregation/last $last
-
max
public static Accumulator max(java.lang.String field)
Returns the highest value that results from applying an expression to each document in a group of documents that share the same group by key.- Parameters:
field
- the field to process- Returns:
- an Accumulator
- MongoDB documentation
- reference/operator/aggregation/max $max
-
min
public static Accumulator min(java.lang.String field)
Returns the lowest value that results from applying an expression to each document in a group of documents that share the same group by key.- Parameters:
field
- the field to process- Returns:
- an Accumulator
- MongoDB documentation
- reference/operator/aggregation/min $min
-
push
public static Accumulator push(java.lang.String field)
Returns an array of all values that result from applying an expression to each document in a group of documents that share the same group by key.- Parameters:
field
- the field to process- Returns:
- an Accumulator
- MongoDB documentation
- reference/operator/aggregation/push $push
-
sum
public static Accumulator sum(java.lang.String field)
Calculates and returns the sum of all the numeric values that result from applying a specified expression to each document in a group of documents that share the same group by key. $sum ignores non-numeric values.- Parameters:
field
- the field to process- Returns:
- an Accumulator
- MongoDB documentation
- reference/operator/aggregation/sum $sum
-
getAccumulator
public Accumulator getAccumulator()
- Returns:
- the accumulator for this Group
-
getName
public java.lang.String getName()
- Returns:
- the name of the group
-
getSourceField
public java.lang.String getSourceField()
- Returns:
- the source field for the group
-
getProjections
public java.util.List<Projection> getProjections()
- Returns:
- the projections for the group
-
getNested
public Group getNested()
- Returns:
- the nested group
-
-