Novice MongoDB Learning---(v) MongoDB's limit, skip, sort method

Source: Internet
Author: User
Tags mongodb limit

Limit method

If you need to read a specified number of data records in MongoDB, you can use the MongoDB limit method, and the limit () method accepts a numeric parameter that specifies the number of record bars read from MongoDB.

MONGO #进入mongoDB
<span style= "LINE-HEIGHT:16.363636016845703PX;" >use Newsdb #选择NewsDB </span>

Note: If you do not specify a parameter in the limit () method, all data in the collection is displayed.


Skip method

In addition to using the limit () method to read a specified amount of data, we can also use the Skip () method to skip a specified number of data, and the Skip method also accepts a numeric parameter as the number of skipped records.

Db.new.find (). Skip (5). Limit (5) #跳过前5条文档, listing 6-10 clauses

Note:the default parameter for the Skip () method is 0.


Sort method

Using the sort () method to sort data in MongoDB, the sort () method can specify a sorted field by parameter, and use 1 and-one to specify how the sort is sorted, where 1 is in ascending order, and 1 is used in descending order.

Db.new.find ({},{"title": 1,_id:0}). Sort ({"title": -1}) #只显示title属性 and display it in descending order








Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Novice MongoDB Learning---(v) MongoDB's limit, skip, sort method

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.