I am working on a large dataset. Here there are multiple categories and values.
Dataset
category, value
A, 1
B, 1
A, 5
A, 3
A, 7
B, 8
A, 4
B, 5
B, 4
From this, I have to get top 3 records from each category by value.
Eg:
category, value
A, 8
A, 7
A, 5
B, 8
B, 5
B, 4
I need this to be calculated in an efficient way.
Asked
Active
Viewed 74 times
0

Ranjith
- 169
- 1
- 1
- 11
-
1this might help you: http://stackoverflow.com/questions/32885047/mongodb-aggregate-sort-and-limit-within-group – devonj May 19 '17 at 17:16
-
Is there any solution using pymongo? – Ranjith May 19 '17 at 17:21
-
Python syntax is practically identical to the JavaScript syntax as shown in the answer there (albeit without the callbacks, depending on library). Your question however is far to obtuse to answer since it completely lacks demonstration of a valid document structure. So chances are the referenced answer is what you need. But if you believe not, then you need to improve your question. – Neil Lunn May 20 '17 at 00:08
-
Is there any way to do it using mongo aggregate? I am looking for a query which can do this. – Ranjith May 20 '17 at 05:52