$count (aggregation)

APPLIES TO: MongoDB vCore

The $count stage in the aggregation pipeline is used to count the number of documents that pass through the pipeline. This stage outputs a document with a single field containing the count of the documents. It's useful when you need to determine the number of documents that match certain criteria or passed through various stages of transformation in the pipeline.

Syntax

{
  $count: <field>
}

Parameters

Description
field The name of the field in the output document where the count is stored.