$skip
In Amazon DocumentDB, the $skip operator is used to offset the starting point of the query results, allowing you to retrieve a specific subset of the matching documents. This is particularly useful in pagination scenarios, where you want to retrieve subsequent pages of results.
Parameters
-
skip: The number of documents to skip before returning the remaining documents.
Example (MongoDB Shell)
The following example demonstrates how to use the $skip operator to retrieve the second page of results (documents 11-20) from a collection.
Create sample documents
db.collection.insert([ { "name": "Document 1" }, { "name": "Document 2" }, { "name": "Document 3" }, { "name": "Document 4" }, { "name": "Document 5" }, { "name": "Document 6" }, { "name": "Document 7" }, { "name": "Document 8" }, { "name": "Document 9" }, { "name": "Document 10" }, { "name": "Document 11" }, { "name": "Document 12" }, { "name": "Document 13" }, { "name": "Document 14" }, { "name": "Document 15" }, { "name": "Document 16" }, { "name": "Document 17" }, { "name": "Document 18" }, { "name": "Document 19" }, { "name": "Document 20" } ]);
Query example
db.collection.find({}, { "name": 1 }) .skip(10) .limit(10);
Output
[
{ "_id" : ObjectId("..."), "name" : "Document 11" },
{ "_id" : ObjectId("..."), "name" : "Document 12" },
{ "_id" : ObjectId("..."), "name" : "Document 13" },
{ "_id" : ObjectId("..."), "name" : "Document 14" },
{ "_id" : ObjectId("..."), "name" : "Document 15" },
{ "_id" : ObjectId("..."), "name" : "Document 16" },
{ "_id" : ObjectId("..."), "name" : "Document 17" },
{ "_id" : ObjectId("..."), "name" : "Document 18" },
{ "_id" : ObjectId("..."), "name" : "Document 19" },
{ "_id" : ObjectId("..."), "name" : "Document 20" }
]
Code examples
To view a code example for using the $skip command, choose the tab for the language that you want to use: