Returns a document that contains a count of the number of documents input to the stage.
$counthas the following prototype form:
<string>is the name of the output field which has the count as its value.
<string>must be a non-empty string, must not start with
$and must not contain the
myCount would be the output field that contains the count. You can specify another name for the output field.
A collection named
scores has the following documents:
The following aggregation operation has two stages:
$matchstage excludes documents that have a
scorevalue of less than or equal to
80to pass along the documents with
80to the next stage.
$countstage returns a count of the remaining documents in the aggregation pipeline and assigns the value to a field called
The operation returns the following results: