Difference between elemmatch projection and elemmatch queryatch

Guys i am finding hard to understand whats the difference between those two.Please someone explain.Thanks in advance

There are 2 ways to use $elemMatch operator,

Below reference documents clears every doubts of usage with example.

1) $elemMatch (query)

The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria.


2) $elemMatch (projection)

The $elemMatch operator limits the contents of an <array> field from the query results to contain only the first element matching the $elemMatch condition.

1 Like

I think we just discussed this topic here: Find or aggregate in this type of query - #6 by harris