Test the effect of the key location in MongoDB on the query.

Source: Internet
Author: User
Tags testq
Test the effect of the key location on the query in MongoDB: 50 MongoDB development skills: the article "accelerated scanning by establishing hierarchical documents" explains that proper Chromatography can reduce MongoDB's access to fields and increase the speed. I have never thought of such a situation before, but I have never heard of it in relational databases. Now let's test whether this is the case. Clear

Test the effect of the key location on the query in MongoDB: 50 MongoDB development skills: the article "accelerated scanning by establishing hierarchical documents" explains that proper Chromatography can reduce MongoDB's access to fields and increase the speed. I have never thought of such a situation before, but I have never heard of it in relational databases. Now let's test whether this is the case. Clear

Test the effect of the key location in MongoDB on the query.

50 MongoDB development tips: accelerated scanning by establishing hierarchical documents "describes how rational Chromatography can reduce MongoDB access to fields and increase the speed. I have never thought of such a situation before, but I have never heard of it in relational databases. Now let's test whether this is the case.

Listing 1:

01for (var I = 0; I <5000000; I ++) {02 db. testq. insert ({"A": "A" + I, "B": "B" + I, "C": "C" + I, "D ": "D" + I, "E": "E" + I, "F": "F" + I, "G": "G" + I, "H ": "H" + I,}) 03} 04 // query 30 times 05 // start the query after preparing the data. No index is created for all keys. Query by a, B, E, and H respectively. 06for (var I = 0; I <30; I ++) {07 res = db. testq. find ({"A": "A99999 "}). explain (); 08 db. testq. res. insert ({"Type": "A", "idx": I, "res": res}); 09 res = db. testq. find ({"B": "B99999 "}). explain (); 10 db. testq. res. insert ({"Type": "B", "idx": I, "res": res}); 11 res = db. testq. find ({"E": "E99999 "}). explain (); 12 db. testq. res. insert ({"Type": "E", "idx": I, "res": res}); 13 res = db. testq. find ({"H": "H99999 "}). explain (); 14 db. testq. res. insert ({"Type": "H", "idx": I, "res": res}); 15}

Experiment results:

Questions and summary:

1. Is it because MongDB itself has no mode and can store any type and format of data in the same collection. Therefore, all the keys to be scanned in the query.

2. From the results, the faster the key query speed is. You can set the timing to put the frequently used keys for queries in front.

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.