
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MongoDB query to skip documents
To skip documents in MongoDB, use skip(). Let us create a collection with documents −
> db.demo263.insertOne({_id:100}); { "acknowledged" : true, "insertedId" : 100 } > db.demo263.insertOne({_id:200}); { "acknowledged" : true, "insertedId" : 200 } > db.demo263.insertOne({_id:300}); { "acknowledged" : true, "insertedId" : 300 }
Display all documents from a collection with the help of find() method −
> db.demo263.find();
This will produce the following output −
{ "_id" : 100 } { "_id" : 200 } { "_id" : 300 }
Following is the query to skip document −
> result = db.demo263.aggregate([ ... { ... $project: { ... v_id: { $ifNull: [null, [100, 200]] } ... ... } ... }, ... { $unwind: '$v_id' }, ... { $sort: { v_id: 1, _id: 1 } }, ... ... { $skip: 2 }, ... { $limit: 2 } ...]);
This will produce the following output −
{ "_id" : 300, "v_id" : 100 } { "_id" : 100, "v_id" : 200 }
- Related Questions & Answers
- MongoDB query to skip n first documents?
- MongoDB - Query embedded documents?
- Is there any way to skip some documents in MongoDB?
- MongoDB query to add multiple documents
- MongoDB query to group duplicate documents
- How to skip documents while retrieving data from MongoDB, using java?
- How to split MongoDB query and skip 5 values?
- 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
- MongoDB query to match documents that contain an array field
- MongoDB query to find documents with specific FirstName and LastName
- How to fire find query on sub-documents in MongoDB?
- How to update many documents with one query in MongoDB?
Advertisements