MongoDB不使用我的索引数组,布尔值

问题描述

例如,我收集了以下所有文件

{       
       "_id" : ObjectId("2819738917238dgd21873"),"mailIntid" : 10000000,"mailCreated" : "2019-02-08","mailLastModified" : null,"mailReceived" : "2019-02-08","mailSend" : "2019-02-08","hadAttachment" : false,"subject" : "nieuwe vacature ","bodyPreview" : "Test Body","importance" : "normal","isDeliveryRequested" : null,"isReadReceiptRequested" : false,"isRead" : false,"isDraft" : false,"inferenceClassification" : "focused","bodyContentType" : "html","senderName" : "Jobs","senderEmail" : "nor[email protected]","fromName" : "Jobs","fromEmail" : "nor[email protected]","flagStatus" : "notFlagged","urls" : "https://test.nl/request-details?id=1337","insertDate" : "2019-02-09","modifiedDate" : "2019-05-05","parseComplete" : true,"rawMailUrl" : [                                                                                                                                                    
               {                                                                                                                                                           
                       "url" : "https://test.nl/request-details?id=1337","parsed" : false                                                                                                                                    
               }                                                                                                                                                           
       ]                                                                                                                                                                   
}

我用以下代码创建了一个索引:

db.testAB.createIndex(
    {"rawMailUrl.parsed": 1},{partialFilterExpression: { "rawMailUrl.parsed": false}}
)

但是,每当我使用以下查询时,它都不会使用上方的索引。

db.testAB.find({"rawMailUrl.parsed": false})

有什么想法吗?用数组和真假表达式创建索引时,我做错什么了吗?

解决方法

您为partialFilterExpression: { "rawMailUrl.parsed": false}定义了索引,即索引中的所有记录具有相同的值false

具有较少的不同值的索引是不好的索引,它不能改善访问路径。因此,不使用索引,只是浪费磁盘空间。