public class SortByCountOperation extends Object implements AggregationOperation
$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 } }.
Aggregation.sortByCount(String) instead of creating instances
of this class directly.| Constructor and Description |
|---|
SortByCountOperation(AggregationExpression groupByExpression)
Creates a new
SortByCountOperation given a group-by expression. |
SortByCountOperation(Field groupByField)
Creates a new
SortByCountOperation given a group-by field. |
| Modifier and Type | Method and Description |
|---|---|
String |
getOperator()
Return the MongoDB operator that is used for this
AggregationOperation. |
org.bson.Document |
toDocument(AggregationOperationContext context)
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waittoPipelineStagespublic SortByCountOperation(Field groupByField)
SortByCountOperation given a group-by field.groupByField - must not be null.public SortByCountOperation(AggregationExpression groupByExpression)
SortByCountOperation given a group-by expression.groupByExpression - must not be null.public org.bson.Document toDocument(AggregationOperationContext context)
AggregationOperationtoDocument in interface AggregationOperationcontext - the AggregationOperationContext to operate within. Must not be null.public String getOperator()
AggregationOperationAggregationOperation. Aggregation operations should
implement this method to avoid document rendering.getOperator in interface AggregationOperationAggregationOperation.Copyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.