Skip to content

Explain

  • MongoDB

Explain shows how the server runs your query: which indexes it uses, how many keys and documents it examined, how many it returned and how long it took. The plan is drawn as a tree of stages. A collection scan (COLLSCAN) is flagged, so a query that reads every document stands out.

  1. Set up the query in the collection tab, or the pipeline in the aggregation editor.
  2. In the collection tab, choose Explain in the toolbar to run the query on the server and measure it. The Explain section opens with the result; there, Run full explain runs it again and Plan only shows the chosen plan without running the query. In the aggregation editor, choose Explain or Plan only in its toolbar.
  3. In the collection tab, choose Result to go back to the documents and Explain to return to the plan.

The top of the view says either:

  • “COLLSCAN: the query reads every document of the collection. An index on the filtered or sorted fields avoids that.” The collection scan stage is highlighted in the plan too.
  • “Uses index …” with the names of the indexes the plan uses.

Below that are four figures:

Figure Meaning
Returned Documents the query returned.
Keys examined Index keys the server read.
Docs examined Documents the server read.
Time Execution time in milliseconds.

With Plan only the query was not run, so there are no counts.

The plan is a tree of stages, such as IXSCAN or COLLSCAN. Each stage shows its index, the documents it returned and its time, with details such as keysExamined, docsExamined, keyPattern, filter, sortPattern and direction. Raw explain output shows the server’s full answer as JSON.

If the plan shows COLLSCAN for a query you run often, create an index on the fields the query filters or sorts on in the index manager, then choose Explain again. The plan then shows an IXSCAN stage on the new index.

Documents Querybara 0.1.19 · built from89dc752