MongoDB查询非常慢(使用索引)

这是我的查询

db.getcollection("images").find({
    "$and": [
        { "text": { "$ne": null } },{ "text": { "$ne": "" } },],"width":"3120"

})

explain结果:

{ 
    "queryPlanner" : {
        "plannerVersion" : 1.0,"namespace" : "mhxy.images","indexFilterSet" : false,"parsedQuery" : {
            "$and" : [
                {
                    "width" : {
                        "$eq" : "3120"
                    }
                },{
                    "text" : {
                        "$not" : {
                            "$eq" : null
                        }
                    }
                },{
                    "text" : {
                        "$not" : {
                            "$eq" : ""
                        }
                    }
                }
            ]
        },"queryHash" : "7DCCCA85","planCacheKey" : "5D3F5173","winningPlan" : {
            "stage" : "FETCH","filter" : {
                "$and" : [
                    {
                        "text" : {
                            "$not" : {
                                "$eq" : null
                            }
                        }
                    },{
                        "text" : {
                            "$not" : {
                                "$eq" : ""
                            }
                        }
                    }
                ]
            },"inputStage" : {
                "stage" : "IXSCAN","keyPattern" : {
                    "width" : 1.0
                },"indexName" : "idx_width","isMultiKey" : false,"multiKeyPaths" : {
                    "width" : [

                    ]
                },"isUnique" : false,"issparse" : false,"isPartial" : false,"indexVersion" : 2.0,"direction" : "forward","indexBounds" : {
                    "width" : [
                        "[\"3120\",\"3120\"]"
                    ]
                }
            }
        },"rejectedPlans" : [
            {
                "stage" : "FETCH","filter" : {
                    "width" : {
                        "$eq" : "3120"
                    }
                },"inputStage" : {
                    "stage" : "IXSCAN","keyPattern" : {
                        "text" : 1.0
                    },"indexName" : "idx_text","multiKeyPaths" : {
                        "text" : [

                        ]
                    },"indexBounds" : {
                        "text" : [
                            "[MinKey,undefined)","(null,\"\")","(\"\",MaxKey]"
                        ]
                    }
                }
            },{
                "stage" : "FETCH","keyPattern" : {
                        "text" : 1.0,"width" : 1.0
                    },"indexName" : "idx_text_width","multiKeyPaths" : {
                        "text" : [

                        ],"width" : [

                        ]
                    },MaxKey]"
                        ],"width" : [
                            "[\"3120\",\"3120\"]"
                        ]
                    }
                }
            }
        ]
    },"serverInfo" : {
        "host" : "...","port" : 27017.0,"version" : "4.2.1","gitVersion" : "edf6d45851c0b9ee15548f0f847df141764a317e"
    },"ok" : 1.0
}

此集合的大小超过13Gb。并记录如下:

{ 
    "_id" : ObjectId("5dbac8665ef144e92017e190"),"o_img" : BinData(0,"/9j/4AAQSkZJRgABAQAAAQABAAD/4gIo.. 1103798 more bytes"),"c_img" : BinData(0,"/9j/4AAQSkZJRgABAQAAAQABAAD/4gIo.. 81058 more bytes"),"date" : ISODate("2019-10-31T11:41:26.238+0000"),"text" : "....","correct_text" : "....","bit" : "119667","width" : "3120","height" : "1440"
}

似乎查询过程的每一步都触及索引。

但是查询至少需要20秒。

此外,我发现mongodb占用了计算机内存的90%以上。

我的计算机内存是否太小?我可以使mongodb不能将二进制数据加载到内存中吗?

libaisong1114 回答:MongoDB查询非常慢(使用索引)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3167996.html

大家都在问