OPTIONS

Measure Index Use

Synopsis

Query performance is a good general indicator of index use; however, for more precise insight into index use, MongoDB provides a number of tools that allow you to study query operations and observe index use for your database.

See also

Index Concepts and Indexing Tutorials for more information.

Operations

Return Query Plan with explain()

Append the explain() method to any cursor (e.g. query) to return a document with statistics about the query process, including the index used, the number of documents scanned, and the time the query takes to process in milliseconds.

Control Index Use with hint()

Append the hint() to any cursor (e.g. query) with the index as the argument to force MongoDB to use a specific index to fulfill the query. Consider the following example:

db.people.find( { name: "John Doe", zipcode: { $gt: "63000" } } } ).hint( { zipcode: 1 } )

You can use hint() and explain() in conjunction with each other to compare the effectiveness of a specific index. Specify the $natural operator to the hint() method to prevent MongoDB from using any index:

db.people.find( { name: "John Doe", zipcode: { $gt: "63000" } } } ).hint( { $natural: 1 } )

Instance Index Use Reporting

MongoDB provides a number of metrics of index use and operation that you may want to consider when analyzing index use for your database: