[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:
Duplicate
duplicates SERVER-9377 Allow collecting "top" N values for e... Closed
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:

  • Select all documents with the "Group" property between X and Y
  • Group by the "Group" property
  • In each group: pick only the K documents with the largest "Value" property

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 SERVER-9377

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