MongoDB - Analyzing Queries
MongoDB - Analyzing Queries In this chapter will analyze the often used $provide an explanation for and $trace queries
Using $provide an explanation for
The $provide an explanation for operator provides records at the question, indexes utilized in a question and different facts. It is quite easy use while studying how nicely your indexes are optimized.We will now use $provide an explanation for on the subsequent query
>db.users.discover(gender:"F",user_name:1,_id:zero).explain()The above provide an explanation for() question returns the subsequent analyzed result
"cursor" : "BtreeCursor gender_1_user_name_1", "isMultiKey" : false, "n" : 1, "nscannedObjects" : 0, "nscanned" : 1, "nscannedObjectsAllPlans" : 0, "nscannedAllPlans" : 1, "scanAndOrder" : false, "indexOnly" : actual, "nYields" : 0, "nChunkSkips" : 0, "millis" : zero, "indexBounds" : "gender" : [ [ "M", "M" ] ], "user_name" : [ [ "$minElement" : 1 , "$maxElement" : 1 ] ]We will now have a look at the fields on this result set indexOnly indicates that this query has used indexing. Cursor field specifies the type of cursor used.BTreeCursor type indicates that an index become used and additionally gives the call of the index used n suggests the wide variety of documents matching again.NscannedObjects shows the overall number of documents scanned.Nscanned suggests the whole quantity of documents or index entries scanned.
The $hint operator forces the query optimizer to use the specified index to run a query.