MongoDB Limit Select Skip Skip Sort Sort MongoDB-7

Source: Internet
Author: User
Tags mongodb mongodb limit

We have learned about MongoDB's find () query function, in relational database selection (limit), sorting (sort) MongoDB also have, and use is more simple

First, let's take a look at adding a few document in

Now there are four document according to them, to the Limit Skip Sort respectively to learn the last a hodgepodge

1. Limit selection: How many I want to remove from these Document

Make a small example: I only need 2 Document

The result is obvious, very naked, very naked.

But I still have to explain: limit (2) is to select two document, starting from the entire collection of the first document to select two

What if we don't want to start with the first document?

2.Skip Skip: How many document I want to skip

A small example: I'm going to skip the first two document starting with the third document directly

The result is still obvious, very naked.

According to international practice to explain: Skip (2) is to skip two document, from the whole collection the first document started jumping, jump back two

Another example: Skip the first one and start with the second one directly.

The problem is, I just want the second and the third how to deal with it?

3.Limit + Skip: Pick from here to there

This is just the problem, a small example: I just want the second and third, how to deal with it?

International practice: Skip the first document select two document from the second article

Don't worry, there's another way.

The results are exactly the same for both, but the interpretation of international practice is different.

International practice: Select two document But to skip the first document select from the second article

Around the half-day, all dizzy, pay attention to the special attention here!!!!!! Here are two ways of writing, must be sure to remember one, because just remember one on the line, completely no difference, a Chinese understanding, one is the understanding of other countries

4. Sort order: Sort results by keyword

Take a small example: Find the document in ascending order by price | Descending arrangement

International practice: Ascending according to the Price field, 1 ascending, 1 descending

5. Limit + Skip + Sort mash up

One example: Select the second third and sort by price in ascending order

The problem arises, shouldn't it be 9800 and then 19800?

Here's the point of knowledge.

Emphasis: Sort + skip + Limit is the priority of their subsectors are priority sort followed by Skip last LIMT

Skip + Limit Priority is also the first skip and then limit

See once, can't remember

Look two times, it won't work.

See three times, do it yourself

Do it once, it's better to do it three times.

Practice a deeper impression

MongoDB Limit Select Skip Skip Sort Sort MongoDB-7

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.