MongoDB Limit Document Show-Programmershelper

0
219
Spread the love

Introduction

In this article, we learn MongoDB limit document.If you want to show limit record in MongoDB. You will apply<db.collection.Limit> for limitation.The limit document shows only those record that you have a need.just only one parameter is required to set the limitation.

Prerequisite

It will good to cover my below articles before this.It helps to learn more about MongoDB.In which I explained.Click here Indexing working in MongoDB and MongoDB aggregation working and MongoDB Map- reduce working.

Implementation section

  • Limit() method
  • Skip() method

Limit() method

The following is the basic syntax-

  • <db> is a reserved word.
  • <Collection_name> writes the collection name.
  • <Limit>a reserve word used for Limit numbers document show.
  • Inside the bracket write the document <specific_criteria _for _Limitation>.

Example :<db.Collection.find().limit(5)>

Practical work

Consider we have the following data-

Above document, we have three document. we apply limit() method fetch two document out of three.So following query display two document.

Output:

MongoDB Limit document

If you do not use limit() then its works same like find() method and return all document.

Skip() method

Let me explain another part of the limit() method.If you want to skip first two document and show next two or more then you will use skip method.

The following is basic syntax

  • <db> is a reserved word.
  • <Collection_name> writes the collection name.
  • <Skip>  a reserved word used for Skip numbers of the document shows next document.
  • Inside the bracket write the document <specific_criteria _for _Skip _and _limit>

Example :<db.Collection.find().skip().limit(5)>

So the following query skips one document and displays one document. and show the second document.

output:

Alt tag MongoDB limit document

Conclusion

I wish I could tell you that a great site of MongoDB.you just understands key element above post-MongoDB Limit document. for more, detail about MongoDB limit document, please click here More detail about the limit() and skip() method.You also read my previous lecture.I hope you will understand this lecture.Thank you for reading this lecture. Hope you got the idea. please share it.