查询不使用不区分大小写的正则表达式的不区分大小写的索引?

时间:2018-04-03 20:26:13

标签: mongodb

Heyo,试图找出为什么Mongo没有对查询使用不区分大小写的索引。我们的字段包含区分大小写和不区分大小写的索引:

{ "v" : 1, "key" : { "name.firstName" : 1 }, "name" : "name.firstName_1", }, { "v" : 1, "key" : { "name.lastName" : 1 }, "name" : "name.lastName_1", }, { "v" : 1, "key" : { "email" : 1 }, "name" : "email_1", }, { "v" : 2, "key" : { "email" : 1 }, "name" : "email_1_insensitive", "background" : true, "collation" : { "locale" : "en_US", "caseLevel" : false, "caseFirst" : "off", "strength" : 1, "numericOrdering" : false, "alternate" : "non-ignorable", "maxVariable" : "punct", "normalization" : false, "backwards" : false, "version" : "57.1" } }, { "v" : 2, "key" : { "name.lastName" : 1 }, "name" : "name.lastName_1_insensitive", "ns" : "movement_prod_centrio.parties", "background" : true, "collation" : { "locale" : "en_US", "caseLevel" : false, "caseFirst" : "off", "strength" : 1, "numericOrdering" : false, "alternate" : "non-ignorable", "maxVariable" : "punct", "normalization" : false, "backwards" : false, "version" : "57.1" } }, { "v" : 2, "key" : { "name.firstName" : 1 }, "name" : "name.firstName_1_insensitive", "ns" : "movement_prod_centrio.parties", "background" : true, "collation" : { "locale" : "en_US", "caseLevel" : false, "caseFirst" : "off", "strength" : 1, "numericOrdering" : false, "alternate" : "non-ignorable", "maxVariable" : "punct", "normalization" : false, "backwards" : false, "version" : "57.1" } },

但是,当我们使用不区分大小写的查询进行搜索时,不会使用不区分大小写的索引。

find { find: "parties", filter: { $or: [ { email: { $in: [ /^abc/i ] } }, { name.firstName: { $in: [ /^abc/i ] } }, { name.lastName: { $in: [ /^abc/i ] } } ] }, projection: { topicId: 1, email: 1, name.firstName: 1, name.lastName: 1 }, limit: 100, maxTimeMS: 5000, collation: { locale: "en_US", strength: 1 } } planSummary: IXSCAN { name.firstName: 1 }, IXSCAN { email: 1 }, IXSCAN { name.lastName: 1 } keysExamined:385759 docsExamined:131837 cursorExhausted:1 numYields:3027 nreturned:27 reslen:5055 locks:{ Global: { acquireCount: { r: 6056 } }, Database: { acquireCount: { r: 3028 } }, Collection: { acquireCount: { r: 3028 } } } protocol:op_query 2347ms

我们可以看到查询不是通过#docsExamined使用不区分大小写的正则表达式,也是通过检查使用"indexName" : "name.firstName_1",索引的计划。一直在广泛检查文档,但我们无法在这里找到任何我们做错的事情。有什么想法吗?

0 个答案:

没有答案