[SERVER-4451] Implement Positional Operator $ for Sorting Created: 07/Dec/11 Updated: 07/Apr/23 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Jarom Severson | Assignee: | Backlog - Query Execution |
| Resolution: | Unresolved | Votes: | 10 |
| Labels: | query_triage | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Assigned Teams: |
Query Execution
|
| Participants: |
| Description |
|
Given a collection with the following documents:
This new feature would allow the positional operator ($) to be used to sort by a field of the matched documents inside the array. For example, the following query would sort by the "b" field of the inner documents with "a" equal to 2:
The documents matching documents would then be returned by the cursor in the following order:
------ Related posts: https://groups.google.com/forum/#!topic/mongodb-user/w5ZVI4yraik https://gist.github.com/e9182ceee4dc9de26f15 |
| Comments |
| Comment by Ian Wright [ 07/Aug/18 ] |
|
Workarounds are to use the aggregation framework unfortunately. Example https://stackoverflow.com/questions/51711544/mongo-incorrectly-sorting-on-array-field?noredirect=1#comment90396956_51711544 |
| Comment by Chris [ 05/Aug/12 ] |
|
Is there a workaround for this? |