How to slice some fileds in aggregation query MongoDB

The lines field is inside lastPoem it should $lastPoem.lines and you have used just $lines in $slice,

  • $addFields after $group stage and before $sort stage
    $addFields: {
      "lastPoem.lines": {
        $slice: ["$lastPoem.lines", 5]


CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top