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

Add an expression to sort an array

    XMLWordPrintable

    Details

    • Case:

      Description

      Syntax:

      {$project:{orderedArray:{$sort:{path:<array-returning-expression>[, sortBy:<someFieldInArray>, <ascending-vs-descending-option>]}}
      

      Examples it should work on:

      Input: {a: [ 1, 10, 5, 3 ]}
      {newA:{$sort:{path:"$a"}}}
      returns:  { newA: [ 1, 3, 5, 10 ] }
       
      Input: { a: [ { x:1, y:99 }, { x: 9, y: 4 } ] }
      {newA: {$sort:{path:"$a", sortBy: "$a.y" }}}
      returns: { newA: [ { x: 9, y: 4 }, { x:1, y:99 } ] }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-query-execution Backlog - Query Execution
              Reporter:
              asya Asya Kamsky
              Participants:
              Votes:
              5 Vote for this issue
              Watchers:
              19 Start watching this issue

                Dates

                Created:
                Updated: