EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials MongoDB Tutorial MongoDB Skip()
Secondary Sidebar
MongoDB Tutorial
  • Commands
    • Mongodb updateMany
    • MongoDB Aggregation
    • Mongodb unwind
    • Mongodb where
    • MongoDB BSON
    • MongoDB Filter
    • Mongodb Match
    • MongoDB sort by date
    • MongoDB Limit()
    • MongoDB Atlas Login
    • MongoDB Relational Database
    • MongoDB count
    • MongoDB Aggregate
    • MongoDB Distinct
    • MongoDB Unique
    • MongoDB find
    • MongoDB findOne()
    • MongoDB insert
    • MongoDB Delete
    • MongoDB Update
    • Lookup in MongoDB
    • order by in MongoDB
    • MongoDB $regex
    • MongoDB $elemMatch
    • MongoDB ObjectId()
    • MongoDB Skip()
    • MongoDB findAndModify
    • Mongodb findOneAndUpdate
    • MongoDB Date Query
    • MongoDB Timestamp
    • MongoDB sort()
    • MongoDB group by
    • MongoDB Join
  • Basics
    • What is MongoDB
    • How To Install MongoDB
    • MongoDB Tools
    • MongoDB GUI Tools
    • MongoDB Versions
    • MongoDB Commands
    • Advantages of MongoDB
    • MongoDB Features
    • Is MongoDB NoSQL
    • Is MongoDB Open Source
    • Build Web Applications using MongoDB
    • MongoDB Data Types
    • MongoDB Administration
    • Data Modeling in MongoDB
    • MongoDB vs Elasticsearch
    • MariaDB vs MongoDB
    • Firebase vs MongoDB
  • Advanced
    • MongoDB Array
    • PostgreSQL ARRAY_AGG()
    • Indexes in MongoDB
    • MongoDB create Index
    • MongoDB Collection
    • MongoDB List Collections
    • MongoDB Capped Collections
    • MongoDB Delete Collection
    • Mongodb show collections
    • MongoDB Auto Increment
    • MongoDB Triggers
    • MongoDB Projection
    • Replication in MongoDB
    • MongoDB Database
    • Mongo DB Create Database
    • MongoDB Compass
    • MongoDB Users
    • MongoDB Authentication
    • MongoDB GridFS
    • MongoDB Relationships
    • MongoDB MapReduce
    • MongoDB Geospatial
    • MongoDB Monitoring
    • Backup in MongoDB
    • MongoDB Sharding
    • MongoDB Java Drivers
    • MongoDB Import
    • Mongo Database Interview Questions
    • MongoDB Join Two Collections
    • MongoDB Group by Multiple Fields
    • MongoDB Pagination
    • MongoDB Replica Set
    • MongoDB Bulk Update
    • MongoDB greater than
    • MongoDB Encryption
    • MongoDB find in array
    • MongoDB like query
    • Mongodb shell
    • MongoDB port
    • MongoDB Query Operators
    • MongoDB Web Interface
    • MongoDB Query Array
    • MongoDB Transactions
    • MongoDB Not In
    • MongoDB not null
    • MongoDB npm
    • MongoDB Remove

Related Courses

MongoDB Certification Course

Oracle Certification Course

All in One Data Science Course

SQL Training Course

Oracle DBA Course

MS SQL Certification Course

MongoDB Skip()

By Priya PedamkarPriya Pedamkar

MongoDB Skip()

Introduction to MongoDB Skip()

MongoDB skip() is used when we required a certain number of results after a certain number of documents simultaneously we have use skip method in MongoDB. If we want to skip a certain number of documents from the collection, skip method will skip the specified documents that we have used with the MongoDB skip method. Skip method in MongoDB will same as an offset used in SQL language, we can also use skip method with the limit. After using the skip method with a limit in MongoDB, it will skip the specified number of documents, and then it will return the result. In this topic, we are going to learn about MongoDB Skip().

Syntax

Below is the syntax of the MongoDB skip method.

1. Skip method

db.collection_name.find ().skip(number of documents that we have skipping)

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,408 ratings)

2. Skip method with a limit

db.collection_name.find ().skip(number of documents that we have skipping).limit(number of documents that we have fetching)

3. Skip method with limit and pretty method

db.collection_name.find ().skip().limit().pretty();

Below is the parameter description syntax of the MongoDB skip method.

1. Collection name: Collection name is defined as that we have used to fetch the data along with the skip method.  We can use any collection name to fetch the data from the collection. We have also use limit and pretty method with skip to fetch the data from the collection.

2. Find: Find method is used with the collection name to fetch the documents using the skip method. If we have not used any skip and limit with the find method, it will return all the collection documents.

3. Limit: The limit method is used to fetch the specific number of the document from the collection. We can use the limit method with the skip method to skip the specific number of documents and return the document of the limited number after skipping the documents.

4. Pretty: Pretty method is used with the skip method to retrieve the result of the collection in formatted order. The pretty method is handy and important.

5. Skip: Skip method in MongoDB used to retrieve document after skipping the specified documents from the collection. The skip method in MongoDB will skip the specified number of documents.

How does MongoDB Skip() method work?

  • Below is the working of the skip method in MongoDB.
  • The limit method will be used to return the maximum number of results from the collection, while the skip method is used to skip the number of documents from the collection in MongoDB.
  • If we have one collection name as a student, student collection contains a hundred documents in it.
  • In student collection, we have to fetch data as 10 documents; simultaneously, we have used collection limits. But the limit will fetch the data as starting 10 documents.
  • When we have fetching data from the series as 11 to 50 then the limit is not working simultaneously, then at that time we have use limit with the number as 40, and skip is used with the number as 10.
  • After using skip with 10, it will skip the first 10 documents from the collection and retrieved result of documents after 10.
  • If we have not used limit with skip then only the first 10 documents are skipped, after skipping 10 documents, all 90 documents result will be retrieved in result set.
  • Skip method with find method is not display the result in a formatted way, to display the result with formatted way then we have used a pretty method with a skip in MongoDB.
  • Skip in MongoDB will skip the specified number of documents that were pass documents into the first stage, and remaining documents will pass into the next stage in the pipeline order.
  • Skip in MongoDB will have the following form are as follows.

{ $skip: <+ve number>}

  • The negative number is not allowed with a skip in MongoDB; it will display the message as “Skip value must be non-negative but received: -1”.
  • In the below example, we have used value as -1 with skip method; it will not display the output result because the negative value is not allowed in the skip method.
  • We need to define only a positive number with the skip method when retrieving data from the collection.

db.test_skip.find().skip(-1)

MongoDB Skip() output 1

Examples of MongoDB Skip()

Below is the example of the skip method in MongoDB.

Example #1 – Skip method

db.test_skip. find(). skip (5)

MongoDB Skip() output 2

In the above example, we have skipped the first five documents from the test_skip collection. After skipping 5 documents remaining all the documents will display in output as a result.

We have not used a pretty method to display the result, so the output is not received in formatted order.

Example #2 – Skip method with a limit

db.test_skip. find(). skip (5). limit (5)

MongoDB Skip() output 3

In the above example, we have skipped the first five documents from the test_skip collection, and also we have used limit as 5 with the skip method. After using limit with a skip, it will display documents from the id 6 to id 10.

Example #3 – Skip method with limit and pretty

In the below example, we have to retrieve documents using the limit method with the skip and pretty method in MongoDB.

After using the pretty method, documents will be displayed in formatted order.

db.test_skip. find(). skip (8). limit (2). pretty ()

output 4

Recommended Articles

This is a guide to MongoDB Skip(). Here we discuss how MongoDB Skip() method works with appropriate syntax with respective examples for better understanding. You may also look at the following articles to learn more –

  1. MongoDB Data Types
  2. MongoDB MapReduce
  3. Lookup in MongoDB
  4. MongoDB List Collections
Popular Course in this category
MongoDB Training Program (4 Courses, 2 Projects)
  4 Online Courses |  2 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Oracle Training (14 Courses, 8+ Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
SQL Training Program (7 Courses, 8+ Projects)4.7
Oracle DBA Database Management System Training (2 Courses)4.7
MS SQL Training (16 Courses, 11+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more