- Reference >
- Operators >
- Aggregation Pipeline Stages >
- $skip (aggregation)
$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
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. Values passed to the pipeline which exceed this limit will return a invalid argument error.
Behavior¶
Using $skip with Sorted Results¶
If using the $skip
stage with any of:
- the
$sort
aggregation stage, - the
sort()
method, or - the
sort
field to thefindAndModify
command or thefindAndModify()
shell method,
be sure to include at least one field in your sort that contains
unique values, before passing results to the $skip
stage.
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.
See the following for more information on each: