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.

Similar Reads

$reverse Array Operator in MongoDB

The $reverse Array operator in MongoDB is used to reverse the order of a given array. It is an important operator used in the aggregation pipeline to process the data....

Syntax

The syntax of the $reverseArray operator is:...

MongoDB $reverseArray Operator Examples

To understand it better, let’s look at some examples of the $reverseArray Operator in MongoDB....

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....

Contact Us