Module spring.data.mongodb
Class SortByCountOperation
java.lang.Object
org.springframework.data.mongodb.core.aggregation.SortByCountOperation
- All Implemented Interfaces:
AggregationOperation
Encapsulates the aggregation framework
We recommend to use the static factory method
$sortByCount-operation.
$sortByCount stage is typically used with Aggregation and $facet. Groups incoming documents
based on the value of a specified expression and computes the count of documents in each distinct group.
SortByCountOperation is equivalent to { $group: { _id: <expression>, count: { $sum: 1 } } }, { $sort:
{ count: -1 } }.
We recommend to use the static factory method
Aggregation.sortByCount(String) instead of creating instances
of this class directly.- Since:
- 2.1
- Author:
- Jérôme Guyon, Mark Paluch
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSortByCountOperation(AggregationExpression groupByExpression) Creates a newSortByCountOperationgiven agroup-by expression.SortByCountOperation(Field groupByField) Creates a newSortByCountOperationgiven agroup-by field. -
Method Summary
Modifier and TypeMethodDescriptionReturn the MongoDB operator that is used for thisAggregationOperation.org.bson.DocumenttoDocument(AggregationOperationContext context) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.mongodb.core.aggregation.AggregationOperation
toPipelineStages
-
Constructor Details
-
SortByCountOperation
Creates a newSortByCountOperationgiven agroup-by field.- Parameters:
groupByField- must not be null.
-
SortByCountOperation
Creates a newSortByCountOperationgiven agroup-by expression.- Parameters:
groupByExpression- must not be null.
-
-
Method Details
-
toDocument
Description copied from interface:AggregationOperation- Specified by:
toDocumentin interfaceAggregationOperation- Parameters:
context- theAggregationOperationContextto operate within. Must not be null.- Returns:
- the Document
-
getOperator
Description copied from interface:AggregationOperationReturn the MongoDB operator that is used for thisAggregationOperation. Aggregation operations should implement this method to avoid document rendering.- Specified by:
getOperatorin interfaceAggregationOperation- Returns:
- the operator used for this
AggregationOperation.
-