MongoDB Learning Notes ~ Indexing improves query efficiency

Source: Internet
Author: User

Index this thing everyone will not be unfamiliar, as long as the contact to a slightly larger data, will use this thing, it can improve the speed of queries, a considerable price is to occupy more storage space, which is normal, in line with the "energy conservation constant", haha! Today is the index of MongoDB, in my 5 million data query test, I found that if your query field is not indexed, it is quite scary, a simple query (single field) takes more than 30 seconds, this operation, the basic can think of the server hanging, haha! When the field is indexed, the query speed is MS, the speed within 100 milliseconds is really excited bad, hehe!

Build index Db.tableName.ensureIndex ({"FieldName", 1|-1})

For 5 million of the data index quite need to take a little time, not immediately respond, this will be normal, hehe! Once the index has been added, you can view it by Mongovue This visualizer, or you can use the command db.tableName.getIndexes () directly

After the database background is selected, we can see the space occupied by its collection data and the collection index respectively.

When the table (collection, collection) indexed, our web page test can be seen, the page response in the MS class, very fast!

For a single-table query, MongoDB after adding the index, the execution speed and stability is really trustworthy, in the complex calculation, MongoDB also provides us with the MapReduce function, in a future article will also say it alone!

MongoDB Learning Notes ~ Indexing improves query efficiency

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.