[DOCS-10250] Comment on: "manual/reference/operator/projection/positional.txt" Created: 12/May/17  Updated: 29/Oct/23  Resolved: 02/Nov/17

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Docs Collector User (Inactive) Assignee: Irene Smith
Resolution: Fixed Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
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


Participants:
Days since reply: 6 years, 15 weeks, 1 day ago

 Description   

"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.



 Comments   
Comment by Githook User [ 31/Oct/17 ]

Author:

{'email': 'irenesmith@Irenes-MacBook-Pro.local', 'name': 'Irene Smith'}

Message: DOCS-10250 Edited several places to make it clear that $ and only return the first matching document within an array.

Signed-off-by: kay <kay.kim@10gen.com>
Branch: v3.2
https://github.com/mongodb/docs/commit/2594b7b6c1e8c627a8e57898c60be2d196703617

Comment by Githook User [ 31/Oct/17 ]

Author:

{'email': 'irenesmith@Irenes-MacBook-Pro.local', 'name': 'Irene Smith'}

Message: DOCS-10250 Edited several places to make it clear that $ and only return the first matching document within an array.

Signed-off-by: kay <kay.kim@10gen.com>
Branch: v3.4
https://github.com/mongodb/docs/commit/c7019389ca8857c3ed45a1c72fe6a832ece05868

Comment by Githook User [ 31/Oct/17 ]

Author:

{'email': 'irenesmith@Irenes-MacBook-Pro.local', 'name': 'Irene Smith'}

Message: DOCS-10250 Edited several places to make it clear that $ and only return the first matching document within an array.

Signed-off-by: kay <kay.kim@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/443e4320272dfe8917843b515da68381cbb61fd8

Comment by Irene Smith [ 31/Oct/17 ]

Pushed and pull request created:

https://github.com/mongodb/docs/pull/3068

Comment by Irene Smith [ 03/Oct/17 ]

Changed both instances mentioned in the task to clearly indicate that only the first match is returned from each document.

Generated at Thu Feb 08 08:00:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.