$slice

The `$slice` modifier limits the number of array elements during a $push operation.

Syntax

{
  $push: {
    field: {
      $each: [ <value1>, <value2>, ... ],
      $slice: <num>
    }
  }
}

Parameters

fieldstringrequired

The field to update.

<num>numberrequired

An integer that specifies the number of array elements to keep. If positive, keeps the first n elements. If negative, keeps the last n elements.