In this bankruptcy, we can discover ways to restrict facts using MongoDB.
The Limit() Method
To restriction the records in MongoDB, you want to use limit() method. The method accepts one range type argument, that's the variety of files which you want to be displayed.
Syntax
The primary syntax of limit() technique is as follows −
>db.COLLECTION_NAME.find().limit(NUMBER)
Example
Consider the gathering myycol has the following statistics.
{_id : ObjectId("507f191e810c19729de860e1"), title: "MongoDB Overview"},
{_id : ObjectId("507f191e810c19729de860e2"), title: "NoSQL Overview"},
{_id : ObjectId("507f191e810c19729de860e3"), title: "Tutorials Point Overview"}
Following example will show only documents even as querying the document.
>db.mycol.find({},{"title":1,_id:0}).limit(2)
{"title":"MongoDB Overview"}
{"title":"NoSQL Overview"}
>
If you don't specify the wide variety argument in limit() approach then it'll display all documents from the gathering.
MongoDB Skip() Method
Apart from restrict() approach, there is one extra technique skip() which additionally accepts variety type argument and is used to bypass the wide variety of documents.
Syntax
The primary syntax of pass() technique is as follows −
>db.COLLECTION_NAME.find().limit(NUMBER).skip(NUMBER)
Example
Following instance will display handiest the second record.
>db.mycol.find({},{"title":1,_id:0}).limit(1).skip(1)
{"title":"NoSQL Overview"}
>
Please notice, the default fee in bypass() approach is zero.