$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$skipstage has the following prototype form:$skip阶段具有以下原型形式:{ $skip: <positive 64-bit integer> }$skiptakes 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阶段与以下任一项一起使用:
the$sortaggregation stage,$sort聚合阶段,thesort()method, orsort()方法,或者thesortfield to thefindAndModifycommand or thefindAndModify()shell method,findAndModify命令或findAndModify()shell方法的sort字段,
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对它在管道中传递的文档的内容没有影响。