MongoDB执行优化的问题
When you have a sequence with $sort followed by a
$skip followed by a $limit, an optimization occurs that moves the $limit operator before the $skip operator.
For example, if the pipeline consists of the following stages:
{ $sort: { age : -1 } },
{ $skip: 10 },
{ $limit: 5 }
During the optimization phase, the optimizer transforms the sequence to the following:
{ $sort: { age : -1 } },
{ $limit: 15 }
{ $skip: 10 }
上面为什么要把$limit放在$skip前就能起优化作用呢?