MongoDB Learning Note 03

Source: Internet
Author: User

Limit the number of returned numbers for the result to use limit, skip

Sort uses an object as a parameter: a set of key/value pairs, keys that correspond to the key names of the document, values that represent the direction of the sort (1: Ascending, 1: Descending), and if more than one key is specified, the order of multiple keys is sorted.

MongoDB handles different types of data in one order, sometimes the value of a key may be of many types, for this mixed type of key ordering, its ordering is pre-defined, from small to large, the order is as follows:

Skipping over a small number of documents is still possible, but if there is a lot of it, skip becomes very slow (you can avoid skipping too large by having query criteria built into the document itself, or using the last result to calculate the next query)

The query is divided into two categories: packaged and normal. The wrapper query is to wrap the query in a larger document

When a document is queried, and the document is processed, when it is saved back to the database, if the volume of the document is increased and there is not enough space to reserve, you need to move it, usually moving it to the end of the collection, so that the results return the document that has been moved. To solve this problem is to take a snapshot of the query, if the "$snapshot" option is used, the query is run against the Invariant collection view. All queries that return a set of results actually take a snapshot.

Cursors consume memory and other resources, the cursor passes through the results, or the client single message requests termination, the database frees the resources, and the freed resources can be used for the database. When the cursor completes the iteration of the matching result, it clears itself, and when the cursor is no longer in scope for the client, the driver sends a special message to destroy the cursor, even if the user does not iterate through all the results, and the cursor is still in scope, not used for 10 minutes, and the database cursor is automatically destroyed. If you want the cursor to last longer, most drivers will implement a function called immortal or a similar mechanism to tell the database not to let Super, which will be closed after the result of the iteration, otherwise it will always consume server resources in the database.

MongoDB Learning Note 03

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.