The eight optimization techniques of "MongoDB" MongoDB

Source: Internet
Author: User

Tip One, minimizing disk access to memory access is much faster than disk access. So the essence of using optimization is to reduce access to the disk as much as possible.
Memory is read 1 million times times faster than disk speed. It takes a long time to read the disk. Several simple ways: Use SSD (SSD), increase memory can reduce hard disk read, let common documents in memory; second, using indexes to reduce memory footprint indexes is ordered, so you don't have to traverse all the items. When the query is indexed to the results of the index, then the eligible documents are loaded into memory, thus reducing memory consumption. Technique three, do not use the index everywhere here to note that not all queries can be indexed. Indexes are typically used when returning results that are only a small fraction of the overall data. Based on experience, the index is not used once you want to return about half of the data in the collection.
If you have already indexed a field and want to use it in a large-scale fuzzy query (because it might be inefficient), you can use a natural sort and use {"$natural": 1} to force MongoDB to disable indexing. The natural sort is "return data in the order of storage on disk" so that MongoDB does not use the index. Tip: Index Overlay Query If you want to return only certain fields and all of them can be placed in the index, Mong oDB can do an index overlay query (covered index query), which does not access the document pointed to by the pointer, and returns the result directly from the indexed data.
For example: Db.foo.ensuIndex ({x:1, y:1,z:1}) Now queries the fields that are indexed and only requires that these fields be returned, and MongoDB does not need to load the entire document. Db,foo.find ({x:ceriteria, y:ceriteria})
Such a query accesses only the data of the index and does not have access to the entire set of data; Technique v. Using composite indexes to speed up multiple query queries you can take advantage of indexes as long as they match the beginning of the index, so consider all the fields that these queries depend on when you create the index. The order of the indexed fields is defined according to the frequency of each field query. Technique VI, by establishing a hierarchical document to speed up the scan the array is organized hierarchically, not only to make it look more organized, but also to allow MongoDB to query quickly when there are no indexes at all. If the document has no hierarchy, MongoDB must traverse each field in the document. Reasonable use of hierarchies can reduce MongoDB access to fields.
Seven, and type query key hypothesis to query satisfies the condition, a and C documents, satisfies a document has 40,000, satisfies B's has 9 K, satisfies C is 200, then should use C and B and A such only need to query 200 records.
This means that if a query condition is known to be more stringent, it will be placed at the top of the book; Tip eight: An or type query is exactly the opposite of an and query, with the most matching query statements first, because MongoDB matches a document that is not in the result set each time.







The eight optimization techniques of "MongoDB" MongoDB

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.