@@ -27,27 +27,27 @@ Definition
2727 <aggregation-expressions>` that resolves to an array.
2828
2929 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.
4231
4332 For more information on expressions, see
4433 :ref:`aggregation-expressions`.
4534
4635Behavior
4736--------
4837
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``.
5151
5252.. list-table::
5353 :header-rows: 1
@@ -65,6 +65,9 @@ For more information on expressions, see
6565 * - ``{ $arrayElemAt: [ [ 1, 2, 3 ], 15 ] }``
6666 -
6767
68+ * - ``{ $arrayElemAt: [ "$undefinedField", 0 ] }``
69+ - ``null``
70+
6871Example
6972-------
7073
0 commit comments