SortByCount constructor

SortByCount(
  1. dynamic expression
)

Creates $sortByCount aggregation stage

expression - expression to group by. You can specify any expression except for a document literal.

To specify a field path, use Field. For example:

Dart code:

SortByCount(Field('employee')).build()

Equivalent mongoDB aggregation stage:

{ $sortByCount:  "$employee" }

Although you cannot specify a document literal for the group by expression, you can, however, specify a field or an expression that evaluates to a document. For example, if employee and business fields are document fields, then the following is a valid argument to $sortByCounts:

Dart code:

SortByCount(MergeObjects([Field('employee'), Field('business')])).build()

Equivalent mongoDB aggregation stage:

{ $sortByCount: { $mergeObjects: [ "$employee", "$business" ] } }

Implementation

SortByCount(expression) : super('sortByCount', expression);