- Reference >
- Operators >
- Aggregation Pipeline Operators >
- $isArray (aggregation)
$isArray (aggregation)¶
On this page
Definition¶
Behavior¶
The <expression>
can be any valid expression. For more information on expressions, see
Expressions.
Example | Results | Notes |
---|---|---|
{ $isArray: "hello" } |
false |
"hello" is a string, passed as a string. |
{ $isArray: [ "hello" ] } |
false |
"hello" is a string, passed as part of an argument array. |
{ $isArray: [ [ "hello" ] ] } |
true |
[ "hello" ] is an array, passed as part of an argument array. |
Note
Aggregation expressions accept a variable number of arguments. These arguments are normally passed as an array. However, when the argument is a single value, you can simplify your code by passing the argument directly without wrapping it in an array.
Example¶
Create the warehouses
collection:
Check if the instock
and the ordered
fields are arrays. If both
fields are arrays, concatenate them:
See also