$sort

The `$sort` modifier orders the elements of an array during a $push operation.

Syntax

{
  $push: {
    field: {
      $each: [ <value1>, <value2>, ... ],
      $sort: <sort specification>
    }
  }
}

Parameters

fieldstringrequired

The field to update.

<sort specification>objectrequired

A document that specifies the field or fields to sort by and the respective sort order. Use 1 for ascending, -1 for descending.