Add an expression to sort an array

XMLWordPrintableJSON

    • Fully Compatible
    • QE 2021-11-15
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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 } ] }
      

              Assignee:
              Neil Shweky (Inactive)
              Reporter:
              Asya Kamsky
              Votes:
              5 Vote for this issue
              Watchers:
              24 Start watching this issue

                Created:
                Updated:
                Resolved: