-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Labels:
-
Environment:
*Location*: https://docs.mongodb.com/manual/reference/operator/projection/positional/#proj._S_
*User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
*Referrer*: https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/
*Screen Resolution*: 1280 x 800
*Location*: https://docs.mongodb.com/manual/reference/operator/projection/positional/#proj._S_ *User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36 *Referrer*: https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/ *Screen Resolution*: 1280 x 800
"Both the $ operator and the $elemMatch operator project a subset of elements from an array based on a condition."
This sentence reads like the $ operator will project multiple elements into the result, if more than one element of the array is matched by the query document. While one element is a subset it gives the impression that the operators could project multiple elements. The quoted sentence seems ambiguous and feels to me like it contradicts the first paragraph where it very clearly states the $ and $elemMatch only project the first element.
The page about the $elemMatch projection operator has the same formulation.
"The following query will return any embedded documents inside a grades array that have a mean of greater than 70 and a grade of greater than 90."
I think this sentence is just factually wrong. The query below will only return the first document inside the grades array which matches the query.
Unless I misunderstood how those operators work, clarifying some of the documentation would help others who are looking for a way to filter an array in the projected result. From what I understand the correct way is to use aggregation if you want a result which filters an array.