[SERVER-3073] Sort internal arrays of a document Created: 10/May/11 Updated: 06/Dec/22 Resolved: 01/Jun/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Yanai Franchi | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Done | Votes: | 3 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Assigned Teams: |
Query
|
| Participants: |
| Description |
|
Lets say I have a collection of Person documents. Each Person document contains array of Car JSON inside the Person document (i.e. the array is am attribute called "cars" within the Person documents). Now, suppose you to get the first 20 cars ordered by their color (assuming the cars have this attribute) for persons with age higher than 30 (assume Persons have "age" attribute). Imagine that there are many persons above 30 in the DB, so throwing the burden to the application is NOT feasible. IMO, This is a general case, that is needed whenever you want to apply a "pagination" feature in your application of documents that contains arrays... As I understand this is a limitation for the current MongoDB release, but maybe next versions may support this. |
| Comments |
| Comment by Ian Whalen (Inactive) [ 01/Jun/18 ] |
|
Closing as this is now possible in agg as per Asya's above comment. |
| Comment by Asya Kamsky [ 02/Jun/17 ] |
|
If this is for displaying results flattened then aggregation currently provides a way to do this (after $unwind of array, do $sort). If this is about keeping the array sorted as new values are inserted into it, then update has ability to $sort (https://docs.mongodb.com/manual/reference/operator/update/sort/) |
| Comment by Subraya Mallya [ 02/Jan/12 ] |
|
Any updates on when/if this will be taken up? |