[SERVER-10205] Group and select the top K elements in each group Created: 15/Jul/13 Updated: 10/Dec/14 Resolved: 24/Jul/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Flavien | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
All |
||
| Issue Links: |
|
||||||||
| Participants: | |||||||||
| Description |
|
I would like the ability in the aggregation framework to group and select the top K elements in each group. Here is an example: Let's say I have documents with the following structure: { "_id":..., "Group": 1, "Value": 4 } { "_id":..., "Group": 2, "Value": 8 } { "_id":..., "Group": 1, "Value": 10 }Given X, Y and K, I would like to be able to use the aggregation framework to do the following:
Because K will be much smaller than the size of the collection itself, I would like to be able to do that in a way that is memory efficient. There is a new feature in 2.4 where we can efficiently sort then limit with the aggregation framework. This is basically the same thing, working on groups. I have no preference on which operator should enable this scenario, as long as it is possible to achieve what I just described. |
| Comments |
| Comment by Asya Kamsky [ 24/Jul/13 ] |
|
Duplicate of |