This article mainly introduced about the MONGO index of some of the notes, has a certain reference value, now share to everyone, the need for friends can refer to
Index usage Scenarios
Excellent: Faster query speed
Inferior: Add and delete will incur additional overhead, occupy space
Tips: Returns more than half of the data in a collection, with high efficiency for full table scans
Index base
Basic operations
View index: Db.test.getIndexes ()
CREATE INDEX: Db.test.ensureIndex ({"username": 1},{"Background": True, "name": "Index_test_name"})//There is a large amount of data available for background execution without blocking
Delete index: Db.test.dropIndex ({"username": 1})
View index Size: db.test.totalIndexSize ()
Property
Index Order:
1 is the positive sequence, 1 is reverse order
Order of attention in composite indexes (Id:1, age:-1)
Indexed properties:
Db.test.ensureIndex ({x:1,y:1},{unique:true})
Db.test.ensureIndexx ({},{sparse:true/false}) is not sparse (default): 1. You can insert data that does not exist in the indexed field, NULL; 2. Can filter non-existent fields: Db.test.find ({m:{$exist: ture}) Sparse:
Optimization Analysis method
Cursor return cursor type (basiccursor or btreecursor) nscanned Number of documents scanned n number of documents returned Millis time (ms) Indexbounds Index used
Db.test.find ({"Age": +}). Hint ({"name": 1, "Age": 1})//. Hint (name_1_age_1)
Tips
Automatic adjustment of Query condition order
Can be a prefix-type regular expression hit index (/^z/)
Indexing keys that require a large number of sort to prevent all data from being loaded into memory
$ne, $nin do not use indexes
Type of index
_ID Index
Single-Touch indexing
Multi-Key indexing
Composite Index
Expired Index
Full-Text Indexing
Location Index
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!