KeyTakeAways on MongoDB $reverseArray Operator
- The MongoDB $reverseArray operator is used in the aggregation pipeline stages to reverse the order of elements in an array.
- It accepts an array expression as an argument and returns an array with the elements in reverse order.
- If the argument does not resolve to an array or null, then this operator will give an error.
- If the entered argument resolves a null value, then this operator will return null.
- If the entered argument refers to a missing field, then this operator will return null.
- If the entered argument is an empty array, then this operator will return an empty array.
- If the entered argument contains subarrays, then this operator will work on the top-level array elements and will not reverse the contents of subarrays.
MongoDB $reverseArray Operator
MongoDB $reverseArray operator reverses the order of the elements of the specified array.