Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-23029

Aggregation should have a $reverseArray expression.

    • Fully Compatible
    • Query 11 (03/14/16)

      Syntax

      {$reverseArray: <expression which evaluates to an array>}
      

      Examples

      Input

      {_id: 0, a: [1, 2, 3]}
      

      Pipeline

      db.coll.aggregate([{
          $project: {
              reversed: {$reverseArray: "$a"}
          }
      }])
      

      Output

      {_id: 0, reversed: [3, 2, 1]}
      

      Additional Notes

      • Can be used in combination with $reduce to yield the equivalent of a $foldR.
      • Returns null if input is nullish.
      • Errors if input is not an array or nullish.

      Original Description

      Aggregation should support an $reverseArray expression, which accepts as input an expression that evaluates to an array, and outputs the reversed version of the array. Throws an error if the input is not an array or nullish.

            Assignee:
            benjamin.murphy Benjamin Murphy
            Reporter:
            benjamin.murphy Benjamin Murphy
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: