@@ -29,27 +29,27 @@ Definition
2929 <aggregation-expressions>` that resolves to an array.
3030
3131 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.
4433
4534 For more information on expressions, see
4635 :ref:`aggregation-expressions`.
4736
4837Behavior
4938--------
5039
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``.
5353
5454.. list-table::
5555 :header-rows: 1
@@ -67,6 +67,9 @@ For more information on expressions, see
6767 * - ``{ $arrayElemAt: [ [ 1, 2, 3 ], 15 ] }``
6868 -
6969
70+ * - ``{ $arrayElemAt: [ "$undefinedField", 0 ] }``
71+ - ``null``
72+
7073Example
7174-------
7275
0 commit comments