gpt4 book ai didi

未使用MongoDB索引

转载 作者:行者123 更新时间:2023-12-03 16:25:43 25 4
gpt4 key购买 nike

我有一些问题的索引已修改。

{
"v" : 1,
"key" : {
"modified" : 1
},
"name" : "modified_1",
"ns" : "app23568387.questions",
"background" : true,
"safe" : null
}

但是,当我查询字段已修改的问题时,mongo不会使用此索引。
db.questions.find({modified: ISODate("2016-07-20T20:58:20.662Z")}).explain(true);

它返回
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 0,
"nscannedObjects" : 19315626,
"nscanned" : 19315626,
"nscannedObjectsAllPlans" : 19315626,
"nscannedAllPlans" : 19315626,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 384889,
"nChunkSkips" : 0,
"millis" : 43334,
"allPlans" : [
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 0,
"nscannedObjects" : 19315626,
"nscanned" : 19315626,
"scanAndOrder" : false,
"indexOnly" : false,
"nChunkSkips" : 0
}
],
"server" : "c387.candidate.37:10387",
"filterSet" : false,
"stats" : {
"type" : "COLLSCAN",
"works" : 19624020,
"yields" : 384889,
"unyields" : 384889,
"invalidates" : 3,
"advanced" : 0,
"needTime" : 19315627,
"needFetch" : 0,
"isEOF" : 1,
"docsTested" : 19315626,
"children" : []
}
}

当我使用 hint()时,mongo会抛出错误 bad hint
我有另一个具有完全相同索引的文件夹集合,查询使用该索引。 (返回 "cursor" : "BtreeCursor modified_1"explain())

问题和文件夹之间可能有什么区别?即使 getIndexes()返回索引,索引是否也可能“损坏”?如果是这样,我该如何解决?

最佳答案

看来您的索引不是完全在后台构建的。您可以使用db.currentOp()命令进行检查:

https://docs.mongodb.com/v3.0/reference/method/db.currentOp/#currentop-index-creation

还要检查mongod.log以查看索引构建过程中的任何错误。

修复的简单方法是删除索引并重新创建

关于未使用MongoDB索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48235116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com