
- 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
How to split MongoDB query and skip 5 values?
To skip values in MongoDB, use skip() along with limit(). For 5 values, use limit(5). Let us create a collection with documents −
> db.demo633.insertOne({"Value":10}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c0be76c954c74be91e6c1") } > db.demo633.insertOne({"Value":20}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c0bea6c954c74be91e6c2") } > db.demo633.insertOne({"Value":30}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c0bec6c954c74be91e6c3") } > db.demo633.insertOne({"Value":40}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c0bef6c954c74be91e6c4") } > db.demo633.insertOne({"Value":50}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c0bf16c954c74be91e6c5") } > db.demo633.insertOne({"Value":60}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c0bf36c954c74be91e6c6") } > db.demo633.insertOne({"Value":70}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c0bf86c954c74be91e6c7") } > db.demo633.insertOne({"Value":80}); { "acknowledged" : true, "insertedId" : ObjectId("5e9c0bfa6c954c74be91e6c8") }
Display all documents from a collection with the help of find() method −
> db.demo633.find();
This will produce the following output −
{ "_id" : ObjectId("5e9c0be76c954c74be91e6c1"), "Value" : 10 } { "_id" : ObjectId("5e9c0bea6c954c74be91e6c2"), "Value" : 20 } { "_id" : ObjectId("5e9c0bec6c954c74be91e6c3"), "Value" : 30 } { "_id" : ObjectId("5e9c0bef6c954c74be91e6c4"), "Value" : 40 } { "_id" : ObjectId("5e9c0bf16c954c74be91e6c5"), "Value" : 50 } { "_id" : ObjectId("5e9c0bf36c954c74be91e6c6"), "Value" : 60 } { "_id" : ObjectId("5e9c0bf86c954c74be91e6c7"), "Value" : 70 } { "_id" : ObjectId("5e9c0bfa6c954c74be91e6c8"), "Value" : 80 }
Following is the query to split query and skip 5 values −
> var dividePage=2; > db.demo633.find().skip((dividePage-1)*5).limit(5);
This will produce the following output −
{ "_id" : ObjectId("5e9c0bf36c954c74be91e6c6"), "Value" : 60 } { "_id" : ObjectId("5e9c0bf86c954c74be91e6c7"), "Value" : 70 } { "_id" : ObjectId("5e9c0bfa6c954c74be91e6c8"), "Value" : 80 }
- Related Articles
- MongoDB query to skip documents
- MongoDB query to skip first 5 records and display only the last 5 of them
- MongoDB query to skip n first documents?
- MySQL query to skip the duplicate and select only one from the duplicated values
- How to skip blank and null values in MySQL?
- MongoDB query to fetch array values
- MongoDB query to get only distinct values
- MongoDB query to pull multiple values from array
- How to query MongoDB a value with $lte, $in and $not to fetch specific values?
- MongoDB query to get distinct FirstName values from documents
- Ignore NULL and UNDEFINED values while running a MongoDB query
- How to skip documents while retrieving data from MongoDB, using java?
- Display distinctly ordered MongoDB record with skip and limit?
- MongoDB query to 'sort' and display a specific number of values
- MongoDB query to sum specific key values with terminal commands?

Advertisements