MongoDB QuickStart (10)

Source: Internet
Author: User

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"  : objectid5983548781331adf45ec7  " 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)
Note: There are several documents that skip the first few documents for display
Example:

The following example shows only a second document.

>db.  MyCol.  Find({},{"title":1,_id:0}).  Limit(1).  Skip(1){"title":"NoSQL Overview"}>     

Please note that the default value for the Skip () method is 0

MongoDB QuickStart (10)

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.