$skip (aggregation)

On this page本页内容

Definition定义

$skip

Skips over the specified number of documents that pass into the stage and passes the remaining documents to the next stage in the pipeline.跳过传递到该阶段的指定数量的文档,并将剩余的文档传递到管道中的下一个阶段。

The $skip stage has the following prototype form:$skip阶段的原型形式如下:

{ $skip: <positive integer> }

$skip takes a positive integer that specifies the maximum number of documents to skip.接受一个正整数,该整数指定要跳过的最大文档数。

Behavior行为

Using $skip with Sorted Results对排序结果使用$skip

If using the $skip stage with any of:如果将$skip阶段用于以下任何一种情况:

be sure that you are performing a stable sort before passing results to the $skip stage. 在将结果传递到$skip阶段之前,请确保正在执行稳定的排序A stable sort ensures that the sort order of returned documents remains the same across multiple executions of the same sort; especially important when used with the $skip stage.稳定的排序可确保在多次执行相同排序时,返回文档的排序顺序保持不变;与$skip阶段一起使用时尤其重要。

See the following for more information on each:有关每种方法的更多信息,请参阅以下内容:

Example示例

Consider the following example:考虑下面的例子:

db.article.aggregate([
    { $skip : 5 }
]);

This operation skips the first 5 documents passed to it by the pipeline. 此操作跳过管道传递给它的前5个文档。$skip has no effect on the content of the documents it passes along the pipeline.对它通过管道传递的文档的内容没有影响。