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
$elemMatchoperator matches documents that contain an array field with at least one element that matches all the specified query criteria.
2) $elemMatch (projection)
The
$elemMatchoperator limits the contents of an<array>field from the query results to contain only the first element matching the$elemMatchcondition.
1 Like
I think we just discussed this topic here: Find or aggregate in this type of query - #6 by harris