Q49: How do $slice and$elemMatch function in projection specifiers?

  • $slice: Limits array items returned in query results (e.g., { comments: { $slice: 5 } } returns first 5 comments).
  • $elemMatch (Projection): Limits array output to contain strictly the first array element matching specified criteria.
Key Takeaways
  • $slice limits array output lengths or range offsets.
  • $elemMatch projection returns specific matching array items.
Knowledge Check

Which projection operator limits an array field output to return the LAST 3 items of an array?