Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 为什么有这么多扫描对象?_Mongodb_Spatial_Sql Execution Plan - Fatal编程技术网

Mongodb 为什么有这么多扫描对象?

Mongodb 为什么有这么多扫描对象?,mongodb,spatial,sql-execution-plan,Mongodb,Spatial,Sql Execution Plan,我有一个包含以下对象的表: >db.shapes.find() {u id:“P1”,“舒适性”:“餐厅”,“形状”:{“类型”:“点”, “坐标”:[2,2]} {u id:“P2”,“舒适性”:“餐厅”,“形状”:{“类型”:“点”, “坐标”:[2,4]} {u id:“P3”,“舒适性”:“警察”,“形状”:{“类型”:“点”, “坐标”:[4,2]} {u id:“P4”,“舒适性”:“警察”,“形状”:{“类型”:“点”, “坐标”:[4,4]} 以下查询的explain()给出了

我有一个包含以下对象的表:

>db.shapes.find()
{u id:“P1”,“舒适性”:“餐厅”,“形状”:{“类型”:“点”,
“坐标”:[2,2]}
{u id:“P2”,“舒适性”:“餐厅”,“形状”:{“类型”:“点”,
“坐标”:[2,4]}
{u id:“P3”,“舒适性”:“警察”,“形状”:{“类型”:“点”,
“坐标”:[4,2]}
{u id:“P4”,“舒适性”:“警察”,“形状”:{“类型”:“点”,
“坐标”:[4,4]}
以下查询的explain()给出了一个奇怪的结果(我认为):

>db.shapes.find({shape:{$nearSphere:{$geometry:{type:“Point”,坐标:
[0,0]},{id:1,舒适性:1}).limit(2).explain()
{
“游标”:“S2NearCursor”,
“isMultiKey”:错误,
“n”:2,
“非扫描对象”:22,
“未扫描”:22,
“NSCannedobjects计划”:22,
“NSCanendallPlans”:22,
“扫描者”:错误,
“indexOnly”:错误,
“NYELDS”:0,
“跳过”:0,
“米利斯”:1,
“指数边界”:{
},
“服务器”:“DBTest:27017”,
“过滤器集”:错误
}
为什么要扫描这么多对象?我是说,这张桌子只有4张 对象和mongodb扫描22

我感谢你的解释

再见,安德烈


>db.shapes.find({shape:{$nearSphere:{$geometry:{type:“Point”,坐标:
…[0,0]},{id:1,舒适性:1})。限制(2)。解释(1)
{
“游标”:“S2NearCursor”,
“isMultiKey”:错误,
“n”:2,
“非扫描对象”:22,
“未扫描”:22,
“NSCannedobjects计划”:22,
“NSCanendallPlans”:22,
“扫描者”:错误,
“indexOnly”:错误,
“NYELDS”:0,
“跳过”:0,
“米利斯”:1,
“指数边界”:{
},
“所有计划”:[
{
“游标”:“S2NearCursor”,
“isMultiKey”:错误,
“n”:2,
“非扫描对象”:22,
“未扫描”:22,
“扫描者”:错误,
“indexOnly”:错误,
“跳过”:0,
“指数边界”:{
}
}
],
“服务器”:“DBTest:27017”,
“过滤器集”:错误,
“统计数据”:{
“类型”:“限制”,
“工作”:22,
“收益率”:0,
“收益率”:0,
“无效”:0,
"先进":二,,
“需要时间”:20,
“needFetch”:0,
“isEOF”:1,
“儿童”:[
{
“类型”:“投影”,
“工作”:22,
“收益率”:0,
“收益率”:0,
“无效”:0,
"先进":二,,
“需要时间”:0,
“needFetch”:0,
“isEOF”:0,
“儿童”:[
{
“类型”:“GEO_NEAR_2DSPHERE”,
“工作”:22,
“收益率”:0,
“收益率”:0,
“无效”:0,
"先进":二,,
“需要时间”:0,
“needFetch”:0,
“isEOF”:0,
“儿童”:[]
}
]
}
]
}
}

看起来您正在使用版本2.4,并且正在运行版本2.6中修复的版本。如果升级,您可能不会再在explain()输出中看到伪造的nscanned数字。

如果您感兴趣地将$maxDistance值放入,会发生什么情况。我想您在形状字段上有一个2dsphere索引?是的,在形状字段上有一个2dsphere索引。如果添加到查询中,$maxDistance做什么?请显示解释({verbose:true})