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

1 回答 1

4

$not可能对索引很挑剔。将查询重写为:

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

那绝对应该使用索引。

于 2014-09-02T17:14:58.377 回答