美文网首页
MongoDB No Query Solutions

MongoDB No Query Solutions

作者: Maslino | 来源:发表于2016-11-20 14:24 被阅读281次

有次同事在MongoDB中执行一个简单查询的时候,出现了如下错误:

rs1:PRIMARY> db.songs.find({'lyrics': ''})
error: {
    "$err" : "Unable to execute query: error processing query: ns=lyrics.songs limit=0 skip=0\nTree: lyrics == \"\"\nSort: {}\nProj: {}\n No query solutions",
    "code" : 17007
}

查询语句在语法上没有什么问题,但是从错误提示来看,是因为没有query solutions. 这个问题第一次遇到,经过在Google上面搜索发现有人在MongoDB JIRA上面提了一个相关的ISSUE:The $exists operator fails if the field is not indexed when using --notablescan. 看来与notablescan这个选项有关系。在这个ISSUE下面,有人作了如下解释:

As you suspect, the "no query solutions" error message happens because 1) there are no indexed solutions available for the $exists query, and 2) collection scans are disallowed by the notablescan option. Therefore, I'm resolving this issue as "Works as Designed, Backwards Breaking". Thanks for pointing out the behavior change between 2.4 versions and 2.6.0--I'm going to make sure that this gets properly documented by our docs team. Do let us know if you find anything else surprising about 2.6.0!

出现“no query solutions”的原因是查询没有索引可以利用并且全表扫描被禁止。的确,在文首那个出错的查询中,lyrics字段没有索引,所以会导致全表扫描。而开启了notablescan选项后,全表扫描是不允许的。因此我们怀疑服务器开启了notablescan.

可以验证一下:

rs1:PRIMARY> use test;
switched to db test

rs1:PRIMARY> db.test.insert({})
WriteResult({ "nInserted" : 1 })

rs1:PRIMARY> db.test.find()
{ "_id" : ObjectId("57086da1506457408b6ef875") }

rs1:PRIMARY> db.test.find({'not_exist_field': ''})
error: {
    "$err" : "Unable to execute query: error processing query: ns=test.test limit=0 skip=0\nTree: not_exist_field == \"\"\nSort: {}\nProj: {}\n No query solutions",
    "code" : 17007
}

相关文章

  • MongoDB No Query Solutions

    有次同事在MongoDB中执行一个简单查询的时候,出现了如下错误: 查询语句在语法上没有什么问题,但是从错误提示来...

  • springboot 链接mongodb异常

    1.com.mongodb.MongoQueryException: Query failed with erro...

  • mongoDB query command

    模糊查询/common/ 包含common的值/[bt]_common/ 包含b or t or bt 开头_c...

  • MongoDB query notes

    基础 无条件查询: (多)条件查询 条件操作符 $lt $lte $gt $gte $ne $in 包含 $...

  • mongodb文档查询操作

    mongodb使用find()方法执行查询操作, 语法 参数解析 query 可选,指定查询操作条件 proje...

  • MongoDB异常:Query failed with erro

  • Mention Solutions

    Mention Solutions by sennchi Mention Solutions SAS M-B...

  • Mongodb 基础汇总

    仅仅是随手一记就不讲就文风了。。。 注意 mongodb 的 query condition 如果是嵌套文档,那么...

  • Solutions

    【老姐妹音频摘录继续】 @大部分人一说到信仰,就觉得无论遇到任何苦难,这个“信养”就应该帮助人们解脱困苦,或解决难...

  • Solutions

    I should be more braver

网友评论

      本文标题:MongoDB No Query Solutions

      本文链接:https://www.haomeiwen.com/subject/ghcypttx.html