首页 > 解决方案 > 索引未使用嵌套字段层次结构选取,但在展平模式下选取

问题描述

所以我挣扎了 2 周,为什么当我“解释”我的查询时我的索引没有被选中。

我有这个查询:

{ “$and”: [

{   "extraProperties.class": "Residential" }, {   "extraProperties.type": "Sale" }, {   "extraProperties.propertyType": "Condo Apartment" }, {   "extraProperties.propertyTypeStyle": "Apartment" } ] }

上面的查询不会选择这个索引:

{ “extraProperties.class”:1 , “extraProperties.type” : 1, “extraProperties.propertyType”:1,“extraProperties.propertyTypeStyle”:1}

这些天我一直在测试一切,最后我决定扁平化层次结构,现在我的查询看起来像这样:

{ “$and”: [

{ “class”: “Residential” }, { “type”: “Sale” }, { “propertyType”: “Condo Apartment” }, { “propertyTypeStyle”: “Apartment” }

] }

现在上面的查询将选择这个索引:

{ “class”:1 , “type” : 1, “propertyType”:1,“propertyTypeStyle”:1}

有人可以解释那里到底发生了什么吗?!?!

解释结果:

https://drive.google.com/file/d/1bs_mqO-1FEBHQ_FsBWgP2TQ2jeiQz4q_/view?usp=sharing

标签: mongodbmongoosemongodb-query

解决方案


推荐阅读