
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
MongoDB query to skip n first documents?
To skip a specific number of documents, use skip() along with limit. Let us create a collection with documents −
> db.demo246.insertOne({"StudentFirstName":"Chris","StudentLastName":"Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5e46b0d71627c0c63e7dba65") } > db.demo246.insertOne({"StudentFirstName":"John","StudentLastName":"Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5e46b0e21627c0c63e7dba66") } > db.demo246.insertOne({"StudentFirstName":"John","StudentLastName":"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5e46b0ea1627c0c63e7dba67") } > db.demo246.insertOne({"StudentFirstName":"Carol","StudentLastName":"Taylor"}); { "acknowledged" : true, "insertedId" : ObjectId("5e46b0f91627c0c63e7dba68") }
Display all documents from a collection with the help of find() method −
> db.demo246.find();
This will produce the following output −
{ "_id" : ObjectId("5e46b0d71627c0c63e7dba65"), "StudentFirstName" : "Chris", "StudentLastName" : "Brown" } { "_id" : ObjectId("5e46b0e21627c0c63e7dba66"), "StudentFirstName" : "John", "StudentLastName" : "Doe" } { "_id" : ObjectId("5e46b0ea1627c0c63e7dba67"), "StudentFirstName" : "John", "StudentLastName" : "Smith" } { "_id" : ObjectId("5e46b0f91627c0c63e7dba68"), "StudentFirstName" : "Carol", "StudentLastName" : "Taylor" }
Following is the query in MongoDB to skip n first documents −
> db.demo246.find().skip(2).limit(1);
This will produce the following output −
{ "_id" : ObjectId("5e46b0ea1627c0c63e7dba67"), "StudentFirstName" : "John", "StudentLastName" : "Smith" }
- Related Articles
- MongoDB query to skip documents
- MySQL SELECT to skip first N results?\n
- Is there any way to skip some documents in MongoDB?
- MongoDB - Query embedded documents?
- MongoDB query to add multiple documents
- MongoDB query to group duplicate documents
- MongoDB query to skip first 5 records and display only the last 5 of them
- How to skip documents while retrieving data from MongoDB, using java?
- How to split MongoDB query and skip 5 values?
- MongoDB query to convert an array to a map of documents with n attributes?
- Filter documents in MongoDB using simple query?
- MongoDB query to get distinct FirstName values from documents
- MongoDB query to update all documents matching specific IDs
- MongoDB query to implement nor query to fetch documents except a specific document
- How to update many documents with one query in MongoDB?

Advertisements