dongzha0813 2014-08-26 11:03
浏览 19

在php附近 - mongodb空间索引和查询

I am using php to query nearby places.

I have the following geoJSON in mongoDB

{
                "_id": {
                    "$oid": "dsfsdfsdfsdfsdfsdfsdf"
                },
                "type": "Feature",
                "geometry": {
                    "type": "Point",
                    "coordinates": [
                        125.6342343431232,
                        10.121543413333423
                    ]
                },
                "properties": {
                    "name": "Any Place"
                }
}

i want to query near by locations about a point, i have index in php as

$collection->ensureIndex(array("geometry" => "2dsphere"));  

and my query is:

$arr = $collection->find(array('geometry' =>array('near'=>array("geometry"=>array("type"=>"Point","coordinates"=>$longLat),'minDistance' => 1000,'maxDistance' => 5000 ) ), ));
var_dump($arr->explain());

$arr->explain() is not giving me the desired result. What's going wrong if someone can help.

Following is the result

array (size=15)
  'cursor' => string 'BasicCursor' (length=11)
  'isMultiKey' => boolean false
  'n' => int 0
  'nscannedObjects' => int 5
  'nscanned' => int 5
  'nscannedObjectsAllPlans' => int 5
  'nscannedAllPlans' => int 5
  'scanAndOrder' => boolean false
  'indexOnly' => boolean false
  'nYields' => int 0
  'nChunkSkips' => int 0
  'millis' => int 0
  'indexBounds' => 
    array (size=0)
      empty
  'allPlans' => 
    array (size=1)
      0 => 
        array (size=5)
          'cursor' => string 'BasicCursor' (length=11)
          'n' => int 0
          'nscannedObjects' => int 5
          'nscanned' => int 5
          'indexBounds' => 
            array (size=0)
              ...
  'server' => string 'h0043434.mongolab.com:43434' (length=26)

It is returning 'BasicCursor' , instead it should give 'S2Cursor'

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大