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 } }
.
We recommend to use the static factory method 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 |
---|---|
org.bson.Document |
toDocument(AggregationOperationContext context)
|
public 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)
AggregationOperation
toDocument
in interface AggregationOperation
Copyright © 2011–2020 Pivotal Software, Inc.. All rights reserved.