Я хотел сделать покрытую агрегацию и, следовательно, создал индекс со всеми полями, которые используются в запросе. Проблема в том, что объяснение говорит мне, что запрос не распространяется.MongoDB: запрос агрегирования не распространяется, хотя используются только индексированные поля
Я просто не знаю, что я здесь отсутствует ..
Это команду
db.tickets.runCommand(
'aggregate',
{pipeline: [
{$match:{tags:'unread'}},
{$group:{
_id:{acc:'$accountId',cha:'$channelId',ass:'$assignee'},
count:{$sum:1}}}],
explain: true
})
А вот объяснить выход
{ "serverPipeline" : [ { "query" : { "tags" : "unread" }, "projection" : { "accountId" : 1, "assignee" : 1, "channelId" : 1, "_id" : 0 }, "cursor" : { "cursor" : "BtreeCursor tags_1_accountId_1_channelId_1_assignee_1", "isMultiKey" : true, "n" : 18093, "nscannedObjects" : 18093, "nscanned" : 18093, "nscannedObjectsAllPlans" : 18093, "nscannedAllPlans" : 18093, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 13, "nChunkSkips" : 0, "millis" : 61, "indexBounds" : { "tags" : [ [ "unread", "unread" ] ], "accountId" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ], "channelId" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ], "assignee" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ] }, "allPlans" : [ { "cursor" : "BtreeCursor tags_1_accountId_1_channelId_1_assignee_1", "n" : 18093, "nscannedObjects" : 18093, "nscanned" : 18093, "indexBounds" : { "tags" : [ [ "unread", "unread" ] ], "accountId" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ], "channelId" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ], "assignee" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ] } } ], "oldPlan" : { "cursor" : "BtreeCursor tags_1_accountId_1_channelId_1_assignee_1", "indexBounds" : { "tags" : [ [ "unread", "unread" ] ], "accountId" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ], "channelId" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ], "assignee" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ] } }, "server" : "NODE50:27017" } }, { "$group" : { "_id" : { "acc" : "$accountId", "cha" : "$channelId", "ass" : "$assignee" }, "count" : { "$sum" : { "$const" : 1 } } } } ], "ok" : 1 }
Возможный дубликат [Невозможно получить закрытый запрос для использования индекса только в mongodb] (http://stackoverflow.com/questions/14190637/unable-to-get-a-covered-query-to-use-index -только-в-MongoDB) – Rafa