Add $sort as an array operator in the agg framework
$filter and $map and $reduce allowed us to stop using $unwind all the time. I know $sort is likely the most computationally expensive peer function to $filter and $map but there are so many times that I have a field with an array of things (scalars or objects) and I need either the whole array in a sorted order or the first or last thing in the sort, for which I would use $arrayElemAt:[ {$sort: {input: ... }}, 0 ] . I see the $sort function signature looking almost like $filter:
{$sort: {input: <expr that evals to array>,
as: "gg" , // name of local list,
fields: [ {"$$gg.fld1":1}, {"$$gg.fld2":-1}, ... ]
}

feel tree to add comments if $sortArray doesn't meet your expectations
-
version 5.2 (Atlas Rapid release) includes $sortArray expression
https://docs.mongodb.com/v5.2/reference/operator/aggregation/sortArray/
This will be also available in the LTS 6.0 release