mongodb, sort skip limit, pipeline -- Выясняем как тут сортировать данные при агрегации

$sort + $limit Memory Optimization

When a sort immediately precedes a limit in the pipeline, the $sort operation only maintains the top n results as it progresses, where n is the specified limit, and MongoDB only needs to store n items in memory. This optimization still applies when allowDiskUse is true and the n items exceed the aggregation memory limit.

Changed in version 2.4: Before MongoDB 2.4, $sort would sort all the results in memory, and then limit the results to n results.

Optimizations are subject to change between releases.

-- цитата из крайне непонятного момента в документации

vedro-compota's picture

проблема наблюдалась в 3.2 в 3.6 всё норм

то есть не работал запрос вида:


матфак вгу и остальная классика =)