[SERVER-21042] Sorting data within arrays Created: 21/Oct/15 Updated: 22/Oct/15 Resolved: 22/Oct/15 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Boris | Assignee: | Stennie Steneker (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | mongo | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
CentOS 7 |
||
| Attachments: |
|
| Operating System: | ALL |
| Participants: |
| Description |
|
I have very simple collection with data in array. I have explained the case in attached file. |
| Comments |
| Comment by Stennie Steneker (Inactive) [ 22/Oct/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Boris, The sort operation in a find() query applies at the document level and does not reorder fields within a document. In order to sort values within an array and return your desired result, you need to use the aggregation framework:
Example output in MongoDB 3.0.7:
Please note that the SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related community support discussion please post on the mongodb-user group (http://groups.google.com/group/mongodb-user) or Stack Overflow. See our Technical Support page for additional support resources. Regards, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by J Rassi [ 21/Oct/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Pasting contents of attachment "mongodb_issue":
|