$size array expression do in MongoDB?The $size expression returns the number of elements in an array.
It helps you count how many items are inside an array field.
$arrayElemAt work in MongoDB?$arrayElemAt returns the element at a specific position in an array.
Positions start at 0, so $arrayElemAt: [array, 0] gives the first item.
$filter in MongoDB array expressions.$filter lets you select only the elements in an array that match a condition.
It creates a new array with just the items you want.
$size on a field that is not an array?If the field is not an array (including null or missing), $size throws an error.
$filter be combined with $size to count filtered elements?You can use $filter to create a smaller array with only matching elements, then use $size to count how many matched.
$size return when used on an array?$size counts how many elements are inside an array.
Arrays start at index 0, so the third element is at index 2.
$filter do in MongoDB?$filter creates a new array with only elements that meet a condition.
$size is used on a non-array field?$size expects an array and throws an error if given something else.
First filter the array, then count the filtered elements with $size.
$filter to select elements from an array based on a condition.$arrayElemAt and $size can be used together in a query.