$sortArray

The `$sortArray` operator sorts an array based on its elements or a specified sort order.

Syntax

{
  $sortArray: {
    input: "<array>",
    sortBy: "<sort specification>"
  }
}

Parameters

inputstringrequired

An expression that resolves to an array.

sortByobjectrequired

A document specifying the sort order. Use 1 for ascending, -1 for descending.