Cursor Methods and Aggregation Equivalents - what about performance

Chapter 2: User-Facing Backend
Cursor Methods and Aggregation Equivalents

What is the performance difference between doing actions on cursor or with aggregation ?
image

Hey @Anthony_34059

This question made me remember the following post.

1 Like

The combination of limit, sort, skip is actually a unique one in that the query planner does a special kind of optimisation on this combination. It also then varies when between a sharded and non-sharded cluster.

As a result, it would be difficult to say without actually doing a like-for-like Explain Plan comparison between:

  • find().limit().sort().skip()
    and
  • aggregate({$limit}, {$sort}, {$skip}).

i read that using limit, sort, […] methods on a cursor make the job be done server side just like aggregation.

Maybe the first syntax is just a sugar for the second one in this case.

A technical answer of mongo team would be appreciate on this post.

The cursor methods that aggregate() supports are:


Cursor methods limit(), sort(), skip() are not syntactic-sugars for the aggregation stages $limit, $sort, $skip. As already mentioned, you already have the tools to measure performance by using the Explain Plan. If you’re not familiar with the Explain Plan I would recommend that you take the following courses:

  1. M201 MongoDB Performance
  2. M312 Diagnostics and Debugging
1 Like