Details
-
Bug
-
Resolution: Done
-
Major - P3
-
None
-
None
-
None
-
*Location*: https://docs.mongodb.com/manual/reference/operator/aggregation/limit/
*User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
*Referrer*: https://www.google.com/
*Screen Resolution*: 1440 x 900
Description
We seem to have encountered a performance problem with $limit in aggregate queries.
The query is very very slow (half a minute) - when the number of docs passed into the limit step are less than the limit size.
For example, first stage is a $match that only finds 6 docs. Second stage is a sort on an indexed field. Third is a $limit=10.
The query is instantaneous when there are lots of docs returned from stage 1. However, when there are only a few, the aggregate query is very very slow.
Expected behavior: aggregate performance of $limit should be equivalent to a standard query's use of limit.