Array Operators

Operator

Description

Example

$size

Returns the size of the array argument. The argument must resolve to an array

{“$size”: “body”}

$slice

Returns the subset of an array.
Param 1: The master array
Param 2 (optional): the position to start evaluating the array from
Param 3: the number of elements from param 2 to return

{ $slice: [ [ 1, 5, 7, 9 ], 1, 2 ] }

// returns [5, 7]

$isArray

Returns true if the operand is an array

{"$isArray": [1,2,3]}
// returns true

$concatArrays

Returns an array which contains all the arrays concatenated together.

{"$concatArrays": [ [ "medable", "is"], [ "great" ] ] }

//returns ["medable", "is", "great"]

$arrayElemAt

Returns the element in the array at a specified index.

{ $arrayElemAt: [ [ "purple", "orange", "yellow" ], 1 ] }

//returns "orange"