$sliceArray

The $sliceArray operation is used to extract a portion of an array based on a specified range. It allows you to return a subset of elements by defining a start index and an optional count of elements to include. If a negative index is provided, it slices from the end of the array. This operation is useful when working with paginated data, trimming arrays to a specific length, or retrieving only a relevant portion of a dataset.

await Member.$update({
    $where: { 
        age: { 
            $eq: 16 
        } 
    },
    $update: {
       $sliceArray: {
          badges: { $begin: 0, $end: 3 }
       }
    }
});

Last updated