$slice operator not working as expected

Hello @Bojie_Xu, Welcome,

You can refer to the $slice documentation,

  • First argument is the array variable name that you passed correctly
  • Second argument is skip index number, which starts from 0, as you said the first index is not getting recognized so you have to pass 0 here.
  • Third argument is limit, number of elements return from an array after skip index.

Example:

{ key: [0,1,2,3,4,5,6,7,8,9,10] }

Query 1:

// Query 1:
{ key: { $slice: ["$key", 0, 5] } }
// Result
{ key: [0,1,2,3,4] }

Query 2:

// Query 2:
{ key: { $slice: ["$key", 5, 5] } }
// Result
{ key: [5,6,7,8,9] }