2014-09-02 65 views
2

为什么此查询在搜索这些文档时不使用此索引?

我的查询:

{ 
    "unique_contact_method.enrichments": { 
    "$not": { 
     "$elemMatch": { 
     "created_by.name":enrichment_name 
}}}} 

我的索引:

{ key: { "unique_contact_method.enrichments.created_by.name": 1 }, ... } 

我的文档:

{ 
    "created_at": "...", 
    "unique_contact_method": { 
     "type" : "...", 
     "handle": "...", 
     "enrichments": [{ 
      "created_at" : "...", 
      "created_by" : { 
       "name"  : "...", 
       "version" : "..." 
      }, 
      "attrs" : { /* ... */ } 
      }, /* ... */ 
     ], 
     "master_id_doc_id": "..." 
    } 
} 

回答

4

$not可以挑剔使用索引。重写查询为:

{'unique_contact_method.enrichments.created_by.name': {$ne: enrichment_name}} 

那应该肯定使用索引。