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.