
- 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
Is there any way to skip some documents in MongoDB?
Yes, you can skip some documents using skip() in MongoDB. Use limit() to display how many documents you want to display after skipping some. Let us create a collection with documents −
> db.demo682.insertOne({FirstName:"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462a804263e90dac94402") } > db.demo682.insertOne({FirstName:"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462ac04263e90dac94403") } > db.demo682.insertOne({FirstName:"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462af04263e90dac94404") } > db.demo682.insertOne({FirstName:"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462b304263e90dac94405") } > db.demo682.insertOne({FirstName:"Adam"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462ba04263e90dac94406") } > db.demo682.insertOne({FirstName:"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462be04263e90dac94407") } > db.demo682.insertOne({FirstName:"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea462c404263e90dac94408") }
Display all documents from a collection with the help of find() method −
> db.demo682.find();
This will produce the following output −
{ "_id" : ObjectId("5ea462a804263e90dac94402"), "FirstName" : "John" } { "_id" : ObjectId("5ea462ac04263e90dac94403"), "FirstName" : "Sam" } { "_id" : ObjectId("5ea462af04263e90dac94404"), "FirstName" : "Bob" } { "_id" : ObjectId("5ea462b304263e90dac94405"), "FirstName" : "David" } { "_id" : ObjectId("5ea462ba04263e90dac94406"), "FirstName" : "Adam" } { "_id" : ObjectId("5ea462be04263e90dac94407"), "FirstName" : "Chris" } { "_id" : ObjectId("5ea462c404263e90dac94408"), "FirstName" : "Carol" }
Following is the query to skip 3 documents and display 2 −
> db.demo682.find().skip(3).limit(2);
This will produce the following output −
{ "_id" : ObjectId("5ea462b304263e90dac94405"), "FirstName" : "David" } { "_id" : ObjectId("5ea462ba04263e90dac94406"), "FirstName" : "Adam" }
- Related Articles
- Is there any way to skip finally block even if some exception occurs in exception block using java?
- MongoDB query to skip documents
- MongoDB query to skip n first documents?
- Is there any way to see the MongoDB results in a better format?
- Is there any way in MongoDB to get the inner value of json data?
- Is there a way to list collections in MongoDB?
- How to skip documents while retrieving data from MongoDB, using java?
- Is there any way to check if there is a null value in an object or array in JavaScript?
- Is there any easy way to add multiple records in a single MySQL query?
- Is there any way to load an extension in chrome browser using Selenium Webdriver?
- Is there any way to embed a PDF file into an HTML5 page?
- Is there any more efficient way to code this “2 Sum” Questions JavaScript
- Is there a way to limit the number of records in a certain MongoDB collection?
- Is there any way of moving to HTML 5 and still promise multi browser compatibility?
- Is there any way to use values from a JSON object in a MySQL Select statement?\n

Advertisements