1 Viewing the query plan
Db.user.find ({"username": "xxx"}) . Explain ()
Db.doc.find ({"Es_y": "}"). Explain ()
{
"Cursor": "Basiccursor",
"Ismultikey": false,
"N": 0,
"Nscannedobjects": 1,
"Nscanned": 1,
"Nscannedobjectsallplans": 1,
"Nscannedallplans": 1,
"Scanandorder": false,
"IndexOnly": false,
"Nyields": 0,
"Nchunkskips": 0,
"Millis": 0,
"Server": "idc254:27017",
"Filterset": false
}
--------
IndexOnly---Indicate whether the required fields can be returned only with an index, not two times according to the address of the document!
Cursor Indicates whether the index is used
Nscanned is the total number of documents that MONGODB scanned to complete this query.
Millis shows the number of milliseconds that the query is consuming.
N shows the number of query results.
Scanandorder---Indicate if you need to sort in memory!
2 building an index
Db.user.ensureIndex ({"username": 1})
3 Querying all indexes of a collection
Db.doc.getIndexes ()
4 Viewing the operation of the current server
Db.currentop ()
{
"InProg": [
{
"Opid": 486,
"Active": true,
"Secs_running": 2,
"Op": "Getmore",
"NS": "Local.oplog.rs",
"Query": {
},
"Client": "192.168.56.66:37299",
"desc": "Conn2",
"ThreadId": "0x7f1e191d7700",
"ConnectionID": 2,
"Waitingforlock": false,
"Numyields": 0,
"Lockstats": {
"Timelockedmicros": {
"R": Numberlong (89),
"W": Numberlong (0)
},
"Timeacquiringmicros": {
"R": Numberlong (15),
"W": Numberlong (0)
}
}
}
]
}
5 About Indexes
For write operations slow, a collection of up to 64 indexes, usually not more than 2 index number!
6 Creating a composite index
Db.user.ensureIndex ({"Key1": 1, "Key2": 1})
7 Memory Sequencing
If you need to sort in memory and exceed 32MB.
You will get an error!
8 forcing the specified index to query
. Hint ({index ... })
9 Overwrite Index
Simply put, the indexed field is ready to meet the requirements, no more than two times to fetch documents according to the address!
10 Implicit indexing
For example {"Age": 1, "username": 1} can be used as {"Age": 1}!