mongodb3.2 System Learning--5, cursor fuzzy query findandmodify function

Source: Internet
Author: User

1 first describes the process of returning the query results:

When querying, MongoDB is not the one that returns all the documents for the result collection at a time, but instead returns the results of the query in batches of multiple documents, returning the document to memory.

Benefits:

    • Reduced client and server-side query burdens.
    • The result collection of the query is large and returns data in batches, which improves the efficiency.

Precautions

    • If you do not use var keyword when executing a query, the results of the query are automatically iterated 20 times.
    • The cursor cursor returns the first 101 documents or 4 megabytes (who first satisfies the data).
    • Inactive cursors automatically shut down within 10 minutes, or the client actively closes the cursor if the cursor is uniformly effective to use the Cursor.nocursortimeout () instance var mycursor = Db.inventory.find ().   Nocursortimeout (); You must then actively close the cursor cursor.close () or iterate over it, otherwise the system resources will be consumed uniformly.
    • The driver or command line calls the find operation and does not immediately query the data, but waits until the data is actually started (Hasnext) to send the query request.
    • Db.**.find (). Sort ({age:1}). Limit (2). Skip (10) The execution time is independent of the order.
    • Cursor objects Each method returns a cursor, making it easy to make chained calls.

Next more important point: Cursor snapshot

MongoDB has no isolation throughout its life cycle, and may return multiple times the same document when the query result set is large and the update operation is performed on the result set of the query. Cursors may return documents that are moved to the end of the collection because of the size of the MMAPV1 storage engine (the 3.2 version of the storage engine has changed to: Wiredtiger), and the workaround is to take a snapshot of the query, db.**. Find (). Snapshot (); After using the snapshot, the query performs a traversal on the _id index, guaranteeing that each document is returned only once, ensuring consistency of results. However, it slows down the query.

Here's a look at MongoDB's storage engine:

MMAPV1 Storage Engine allocation policy: If a document update operation has checked the pre-allocated space of the document in the disk, MongoDB allocates a larger space on the disk, and the disadvantage is that it will take more time if there are many indexes in the collection. Version 3.0 modifies the default assignment policy to: 2 of the n-th allocation policy. Helps reduce the number of fragments in the system

Reduce the frequency of mobile, improve write efficiency.

mongodb3.2 System Learning--5, cursor fuzzy query findandmodify function

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.