$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 64-bit integer> }

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

Note注意

Starting in MongoDB 5.0, the $skip pipeline aggregation has a 64-bit integer limit. 从MongoDB 5.0开始,$skip管道聚合具有64位整数限制。Values passed to the pipeline which exceed this limit will return a invalid argument error.传递给管道的值超过此限制将返回无效参数错误。

Behavior行为

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

If using the $skip stage with any of:如果将$skip阶段与以下任何一项一起使用:

be sure to include at least one field in your sort that contains unique values, before passing results to the $skip stage.在将结果传递到$skip阶段之前,请确保在排序中至少包含一个包含唯一值的字段。

Sorting on fields that contain duplicate values may return a different sort order for those duplicate fields over multiple executions, especially when the collection is actively receiving writes.对包含重复值的字段进行排序可能会在多次执行时为这些重复字段返回不同的排序顺序,特别是当集合正在主动接收写入时。

The easiest way to guarantee sort consistency is to include the _id field in your sort query.保证排序一致性的最简单方法是在排序查询中包含_id字段。

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.$skip对沿管道传递的文档的内容没有影响。

←  $setWindowFields (aggregation)$sort (aggregation) →