[SERVER-35182] Is it possible to limit the results of a group function? Created: 23/May/18 Updated: 28/Jun/18 Resolved: 23/May/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | AntonisMak | Assignee: | Ramon Fernandez Marina |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
Is it possible to limit the results of group function? I have a huge dataset and I want to group the results by an id and for each id to create an array with coordinates. The output result is:
As I see the code groups all the id's in dataset and the performance is very bad. Code:
If I add $limit in the end of this query, the group function executed and then the limit so there is no change in performance. Is it possible to limit the results of a group function? |
| Comments |
| Comment by AntonisMak [ 23/May/18 ] |
|
But the performance is very low as it must group the entire dataset first, right? Is there a more efficient solution? Thank you! |
| Comment by Ramon Fernandez Marina [ 23/May/18 ] |
|
Thanks for your report. You can use $limit before $group to only group a subset of your data. Please note that the SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag, where your question will reach a larger audience. A question like this involving more discussion would be best posted on the mongodb-user group. See also our Technical Support page for additional support resources. Regards, |