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

Add an expression to sort an array

    XMLWordPrintable

Details

    • Fully Compatible
    • QE 2021-11-15

    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

              Votes:
              5 Vote for this issue
              Watchers:
              24 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: