Limit () method
To limit the records in MongoDB, you need to use the limit () method. The limit () method accepts a numeric parameter, which is the number of documents to display.
Grammar:
The basic syntax for the limit () method is as follows
>db. Collection_name. Find(). Limit(number)
Example
Consider the collection Myycol with the following data
{ "_ID" : ObjectId(5983548781331adf45ec5), "Title":"MongoDB Overview"}{ "_id" : ObjectId(5983548781331adf45ec6), "title": "NoSQL Overview"}{ "_id" : ObjectId(5983548781331adf45ec7 ), "title":"Yiibai Overview"}
The following example will show only 2 documents when executing a document query.
>db.. Find ({},{ "title" :1,< Span class= "PLN" >_id:0}). (2) { "title" : "MongoDB Overview" } { "title" : "NoSQL Overview "}>
If you do not specify the number of parameters for the limit () method, it displays all the files from the collection.
MongoDB Skip () method
In addition to the limit () method, there is a method that skips () also accepts numeric type parameters and uses the number of skipped documents.
Grammar:
The Skip () method has the following basic syntax:
>db. Collection_name. Find(). Limit(number). Skip(number)
Example:
The following example shows only a second document.
>db. MyCol. Find({},{"title":1,_id:0}). Limit(1). Skip(1){"title":"NoSQL Overview"}>
MongoDB Tutorial Lesson 15th MongoDB Restricted Records