MongoDB. mastering_find ()

Source: Internet
Author: User

Field returned by the query

Previously, crud mentioned only selector, but field_selection was not mentioned. In fact, the find () method has two parameters. By default, the second parameter is *, that is, all fields are returned. If you want to return only the specified field, you can write dB. coooooolection. Find ({null, {field1: 1, field2: 2 });. It must be mentioned that "_ id" is a field that must be returned and is numbered 0.

Bytes -------------------------------------------------------------------------------------

Sort

The sort () method has a parameter that specifies who to sort. For example, {field1: 1} is sorted in ascending order by field1; {field1: 1, field2: -1} is to sort by field1 in ascending order and then by field2 in descending order. Of course, it is important to note that if you want to sort massive data, sort is limited, that is, you can only sort the fields that can be indexed. Otherwise, A system error is returned.

Bytes -------------------------------------------------------------------------------------

Paging

The limit (number) and skip (number) methods are used to control paging. Limit determines the maximum number of returned documents. The Skip determines how many documents are skipped and the document is returned. Here, we also need to mention that the limit method is best followed by the sort method, so as to avoid errors in some non-indexed field operations.

Bytes -------------------------------------------------------------------------------------

Count

You can call the count () method to obtain the number of statements returned.

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.