MongoDB Tutorial Lesson 15th MongoDB Restricted Records

Source: Internet
Author: User
Tags mongodb tutorial

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.