executionStats.totalKeysExamined displays 3
to indicate that MongoDB scanned three index entries. The
number of keys examined match the number of documents
returned, meaning that the mongod only had
to examine index keys to return the results. The
mongod did not have to scan all of the
documents, and only the three matching documents had to be
pulled into memory. This results in a very efficient query.

Visual Tree

The Query Performance Summary shows the
execution stats of the query:

Documents Returned displays 3 to indicate
that the query matches and returns three documents.

Index Keys Examined displays 3
to indicate that MongoDB scanned three index entries. The
number of keys examined match the number of documents
returned, meaning that the mongod only had
to examine index keys to return the results. The
mongod did not have to scan all of the
documents, and only the three matching documents had to be
pulled into memory. This results in a very efficient
query.

On the right-hand side of the
Query Performance Summary, MongoDB Compass shows
that the query used the quantity index.

Below the Query Performance Summary, MongoDB Compass
displays the query stages FETCH and IXSCAN.
IXSCAN indicates that the
mongod used an index to satisfy the query
before exeuting the FETCH stage and retrieving the
documents.

Raw JSON

The explain details can also be viewed in raw JSON format by
clicking Raw JSON below the query bar:

Without the index, the query would scan the whole collection of 10
documents to return 3 matching documents. The query also had to
scan the entirety of each document, potentially pulling them into
memory. This results in an expensive and potentially slow query
operation.

When run with an index, the query scanned 3 index entries
and 3 documents to return 3 matching documents, resulting
in a very efficient query.

Mongo Shell

Compass

Compare Performance of Indexes

To manually compare the performance of a query using more
than one index, you can use the hint()
method in conjunction with the explain()
method.