MongoDB|MongoDB No Query Solutions
有次同事在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.
【MongoDB|MongoDB No Query Solutions】可以验证一下:
rs1:PRIMARY> use test;
switched to db testrs1: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
}
推荐阅读
- 关于QueryWrapper|关于QueryWrapper,实现MybatisPlus多表关联查询方式
- mybatisplus如何在xml的连表查询中使用queryWrapper
- mybatisplus|mybatisplus where QueryWrapper加括号嵌套查询方式
- MybatisPlus|MybatisPlus LambdaQueryWrapper使用int默认值的坑及解决
- MybatisPlus使用queryWrapper如何实现复杂查询
- MongoDB,Wondows下免安装版|MongoDB,Wondows下免安装版 (简化版操作)
- 事件代理
- jQuery插件
- 7、前端--jQuery简介、基本选择器、基本筛选器、属性选择器、表单选择器、筛选器方法、节点操作、绑定事件
- SpringBoot整合MongoDB完整实例代码