[SERVER-23029] Aggregation should have a $reverseArray expression. Created: 09/Mar/16  Updated: 14/Mar/17  Resolved: 15/Mar/16

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 3.3.4

Type: New Feature Priority: Minor - P4
Reporter: Benjamin Murphy Assignee: Benjamin Murphy
Resolution: Done Votes: 0
Labels: expression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CSHARP-1608 Aggregation should have a $reverseArr... Closed
Documented
is documented by DOCS-8483 Document reverseArray Closed
Related
is related to DRIVERS-297 Aggregation Framework Support for 3.4 Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 11 (03/14/16)
Participants:

 Description   

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.



 Comments   
Comment by Benjamin Murphy [ 15/Mar/16 ]

This ticket adds the $reverseArray expression to aggregation, which accepts as an argument an expression that evaluates to an array, and produces the reversed value of that array. It should be added to the list of agg expressions in documentation.

Any drivers that translate individual agg expressions will need to be updated to account for this new expression.

Comment by Githook User [ 15/Mar/16 ]

Author:

{u'username': u'benjaminmurphy', u'name': u'Benjamin Murphy', u'email': u'benjamin_murphy@me.com'}

Message: SERVER-23029 Added reverseArray expression to aggregation.
Branch: master
https://github.com/mongodb/mongo/commit/a40991b77d885ceb3048b9eaf3b5100e259234b9

Comment by Charlie Swanson [ 11/Mar/16 ]

After some internal discussion, I've updated the description to match the agreed-upon design.

Generated at Thu Feb 08 04:02:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.