MongoDB Documentation, Release 3.0.4 Query Plans Query Optimization Query Plan Revision For more information see Measure Index Use (page 528). The MongoDB query optimizer processes queries and chooses the most efficient query plan for a query given the available indexes. The query system then uses this query plan each time the query runs. The query optimizer only caches the plans for those query shapes that can have more than one viable plan. The query optimizer occasionally reevaluates query plans as the content of the collection changes to ensure optimal query plans. You can also specify which indexes the optimizer evaluates with Index Filters (page 69). You can use the db.collection.explain() or the cursor.explain() method to view statistics about the query plan for a given query. This information can help as you develop indexing strategies (page 546). db.collection.explain() provides information on the execution of other operations, such as db.collection.update() . See db.collection.explain() for details. To create a new query plan, the query optimizer: If an index returns a result already returned by another index, the optimizer skips the duplicate match. In the case of the two buffers, both buffers are de-duped. The selected index becomes the index specified in the query plan; future iterations of this query or queries with the same query pattern will use this index. Query pattern refers to query select conditions that differ only in the values, as in the following two queries with the same query pattern: db.inventory.find( { type: 'food' } ) db.inventory.find( { type: 'utensil' } ) As collections change over time, the query optimizer deletes the query plan and re-evaluates after any of the following events: • The collection receives 1,000 write operations. Chapter 3. MongoDB CRUD Operations 68 3. stops the testing of candidate plans and selects an index when one of the following events occur: • An unordered query plan has returned all the matching results; or • An ordered query plan has returned all the matching results; or • An ordered query plan has returned a threshold number of matching results: – Version 2.0: Threshold is the query batch size. The default batch size is 101. – Version 2.2: Threshold is 101. • If the candidate plans include both ordered query plans and unordered query plans , there are two common results buffers, one for the ordered plans and the other for the unordered plans. • If the candidate plans include only unordered query plans , there is a single common results buffer. • If the candidate plans include only ordered query plans , there is a single common results buffer. 2. records the matches in a common results buffer or buffers. 1. runs the query against several candidate indexes in parallel.