Question about multikey index.. please help!!

why does it say in documentation that multikey index does not cover queries over array fields when thats what it does

(Under the header Covered queries on this page)

Hello @Harsh_Chaudhary, Welcome to the MongoDB community forum,

I hope you know the difference between a covered query and an indexed query (improves the performance).

If not then refer to this explanation about the covered query:

A covered query is a query that can be satisfied entirely using an index and does not have to examine any documents. An index covers a query when all of the following apply:

  • all the fields in the query are part of an index, and
  • all the fields returned in the results are in the same index.
  • no fields in the query are equal to null (i.e. {"field" : null} or {"field" : {$eq : null}} ).

Specifically for the multi-key index, each array element is indexed separately. So, it does not guarantee that the index alone can satisfy the entire query without examining the documents.

I would suggest you play with explain command, also use MongoDB Compass to visualize and understand the execution and index use by clicking on the Explain button.

1 Like