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