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