search

Home  >  Q&A  >  body text

mongodb covering index not working?

I want to try to use mongodb covering index to improve query performance, but it cannot be achieved. The code is as follows
The picture below is the query statement

The index is as follows

Query Analysis

From the query analysis, we can see that mongodb still queries specific document information, and does not directly return data from the index

阿神阿神2841 days ago796

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-02 09:28:38

    Help answer this question, please pay attention to the following situation:

    1. What you created is a composite index: sale_amount+audit

    2. In your composite index, there are two actual working indexes: sale_amount(prefix index) and sale_amount+audit

    3. Corresponding to your query, you use audit as the condition {audit: true}, and the index will not be used.

    For reference.

    Love MongoDB! Have Fun!

    reply
    0
  • Cancelreply