@@ -27,27 +27,27 @@ Definition
27
27
<aggregation-expressions>` that resolves to an array.
28
28
29
29
The ``<idx>`` expression can be any valid :ref:`expression
30
- <aggregation-expressions>` that resolves to an integer:
31
-
32
- - If the ``<idx>`` expression resolves to zero or a positive integer,
33
- :expression:`$arrayElemAt` returns the element at the ``idx``
34
- position, counting from the start of the array.
35
-
36
- - If the ``<idx>`` expression resolves to a negative integer,
37
- :expression:`$arrayElemAt` returns the element at the ``idx``
38
- position, counting from the end of the array.
39
-
40
- If ``idx`` exceeds the array bounds, :expression:`$arrayElemAt` does
41
- not return a result.
30
+ <aggregation-expressions>` that resolves to an integer.
42
31
43
32
For more information on expressions, see
44
33
:ref:`aggregation-expressions`.
45
34
46
35
Behavior
47
36
--------
48
37
49
- For more information on expressions, see
50
- :ref:`aggregation-expressions`.
38
+ - If the ``<idx>`` expression resolves to zero or a positive integer,
39
+ :expression:`$arrayElemAt` returns the element at the ``idx``
40
+ position, counting from the start of the array.
41
+
42
+ - If the ``<idx>`` expression resolves to a negative integer,
43
+ :expression:`$arrayElemAt` returns the element at the ``idx``
44
+ position, counting from the end of the array.
45
+
46
+ - If ``idx`` exceeds the array bounds, :expression:`$arrayElemAt` does
47
+ not return a result.
48
+
49
+ - If the ``<array>`` expression resolves to an undefined array,
50
+ :expression:`$arrayElemAt` returns ``null``.
51
51
52
52
.. list-table::
53
53
:header-rows: 1
@@ -65,6 +65,9 @@ For more information on expressions, see
65
65
* - ``{ $arrayElemAt: [ [ 1, 2, 3 ], 15 ] }``
66
66
-
67
67
68
+ * - ``{ $arrayElemAt: [ "$undefinedField", 0 ] }``
69
+ - ``null``
70
+
68
71
Example
69
72
-------
70
73
0 commit comments