Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't have any index that mongo will automatically use for that, so it's doing a full table scan.</p> <p>As mentioned in <a href="http://www.mongodb.org/display/DOCS/Indexes#Indexes-CompoundKeys">the docs</a></p> <blockquote> <p>If the first key [of the index] is not present in the query, the index will only be used if hinted explicitly. </p> </blockquote> <p><strong>Why</strong></p> <p>If you have an index on a,b - and you search by <code>a</code> alone - an index will automatically be used. This is because it's the start of the index (which is fast to do), the db can just ignore the rest of the index value. </p> <p>An index on a,b is <strong>inefficient</strong> when searching by <code>b</code> alone simply because it doesn't give the possibility to use the index searching with "starts with thisfixedstring".</p> <p>So, either:</p> <ul> <li>Include _reference_1_id in the query (probably irrelevant)</li> <li>OR add an index on _reference_2_id (if you query by the field often)</li> <li>OR use a hint</li> </ul> <p><strong>Hint</strong></p> <p>Probably your lowest-cost option right now.</p> <p>Add a query hint to force using your <code>_reference_1_id_1__reference_2_id_1_id_1</code> index. Which is likely to be a lot faster than a full table scan, but still a lot slower than an index which starts with the field you are using in the query.</p> <p>i.e. </p> <pre><code>db.mycoll .find({"_reference_2_id" : ObjectId("jkl7890123456")}) .hint("_reference_1_id_1__reference_2_id_1_id_1"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload