Navigation
This version of the documentation is archived and no longer supported.
$size (aggregation)
Definition
-
$size
Counts and returns the total number of items in an array.
$size has the following syntax:
The argument for $size can be any expression as long as it resolves to an array. For
more information on expressions, see Expressions.
Behavior
The argument for $size must resolve to an array. If the
argument for $size is missing or does not resolve to an
array, $size errors.
Example
Consider an inventory collection with the following documents:
The following aggregation pipeline operation uses the
$size operator to return the number of elements in the colors
array:
The operation returns the following: